From: Jakob on 25 Apr 2010 15:17 Hello, My group and I are dealing with MATLAB for the first time and we are analyzing a wind turbine.. We want to see what forces act on the wind turbine during a rotation. ----- intv=2*pi/64 for theta=0:intv:2*pi if 0<=theta<pi/2 alpha = 1 elseif pi/2<=theta<pi alpha = 2 elseif pi<=theta<3/2*pi alpha = 3 else alpha = 4 end alpha end ------ When I run this, I only get alpha = 1.. We have functions instead of "1", "2", "3" and "4".. But I hope you get the point :) Greetings Jakob
From: Tim Love on 25 Apr 2010 15:48 "Jakob " <jhaerv.remove_this.09(a)student.aau.dk> writes: >if 0<=theta<pi/2 This doesn't do what mathematicians expect. Try if 0<=theta && theta<pi/2
From: Matt Dunham on 25 Apr 2010 16:04 "Jakob " <jhaerv.remove_this.09(a)student.aau.dk> wrote in message <hr24fh$7uk$1(a)fred.mathworks.com>... > Hello, > My group and I are dealing with MATLAB for the first time and we are analyzing a wind turbine.. > We want to see what forces act on the wind turbine during a rotation. > > > ----- > intv=2*pi/64 > for theta=0:intv:2*pi > > if 0<=theta<pi/2 > alpha = 1 > elseif pi/2<=theta<pi > alpha = 2 > elseif pi<=theta<3/2*pi > alpha = 3 > else > alpha = 4 > end > > alpha > end > ------ > > When I run this, I only get alpha = 1.. We have functions instead of "1", "2", "3" and "4".. But I hope you get the point :) > > Greetings Jakob Here's what's happening: if 0<=theta<pi/2 Matlab evaluates 0<=theta first, suppose this is true. Matlab then evaluates true < pi/2, and since the right hand side evaluates as a double, true is converted to the double 1, hence 1 < pi/2 is evaluated which will return false. In fact this expression will always return false regardless of the value of theta. What you need is this: if (0 <= theta) && (theta < pi/2)
From: Jakob on 25 Apr 2010 16:35 Thanks a lot to both of you! I got excatly what I needed.. I'm glad you know what I mean, when MATLAB doesn't. Thanks again :) "Matt Dunham" <mattdunham(a)yahoo.com> wrote in message <hr277l$2t1$1(a)fred.mathworks.com>... > "Jakob " <jhaerv.remove_this.09(a)student.aau.dk> wrote in message <hr24fh$7uk$1(a)fred.mathworks.com>... > > Hello, > > My group and I are dealing with MATLAB for the first time and we are analyzing a wind turbine.. > > We want to see what forces act on the wind turbine during a rotation. > > > > > > ----- > > intv=2*pi/64 > > for theta=0:intv:2*pi > > > > if 0<=theta<pi/2 > > alpha = 1 > > elseif pi/2<=theta<pi > > alpha = 2 > > elseif pi<=theta<3/2*pi > > alpha = 3 > > else > > alpha = 4 > > end > > > > alpha > > end > > ------ > > > > When I run this, I only get alpha = 1.. We have functions instead of "1", "2", "3" and "4".. But I hope you get the point :) > > > > Greetings Jakob > > Here's what's happening: > > if 0<=theta<pi/2 > > Matlab evaluates 0<=theta first, suppose this is true. Matlab then evaluates > true < pi/2, and since the right hand side evaluates as a double, true is converted > to the double 1, hence 1 < pi/2 is evaluated which will return false. > In fact this expression will always return false regardless of the value of theta. > > What you need is this: > > if (0 <= theta) && (theta < pi/2)
|
Pages: 1 Prev: how to obtain frequency and power/frequency vectors using Hpsd(...) function Next: xlswrite |