Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: Problem using plots and loops
Replies: 1   Last Post: Feb 3, 2013 11:04 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
dpb

Posts: 6,677
Registered: 6/7/07
Re: Problem using plots and loops
Posted: Feb 3, 2013 11:04 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 2/3/2013 1:06 AM, Ankita wrote:
...

> 1) In the first 2 if loops, I want to make sure that the ratio fits in a
> given limit. Is there any better way of doing that?


You could write things like Nmax=min(InputRatio,Limit) etc., but if it
works as is, that's a nicety and since it's just a single set of values
and is in an user input section the time isn't an issue...I'd let it go
until got other things worked out and develop some more familiarity w/
Matlab and programming in general...

> 2) When I execute
> the program, only the fprintf in 2nd if loop is executed. Why is that?


Would seem to be owing to the values you've selected -- altho it's
possible you've written a set of conditions such that one branch can
never be reached because the tests aren't possible--I didn't have time
at the moment to read it that carefully, sorry...

> 3) For the last for loop, I should be get 4 different curves for 4
> values of N. Instead I get one curve (the curve is actually a set of
> points. Not a continuous line. That too is my problem.)


Compute the points in an array and then plot each line when you have a
set of values for the curve instead of each point as it is calculated.

> %NOSE AND MAIN WHEEL LOAD CALCULATION
...

> B=M_f+N_f;
> if M_f/B<0.20
> if M_f/B>0.1
> Nmax=W*(M_f/B);
> else
> Nmax=W*0.15; %max static load per nose wheel
> fprintf('The M_f/B ratio ...
> end
> end
>
> if M_a/B>0.05
> if M_a/B<0.1
> Nmin=W*(M_f/B);
> else
> Nmin=W*0.08; %min static load per nose wheel
> fprintf('The M_a/B ratio has ...
> end
> end
>

...

> %TOTAL STROKE CALCULATION
> %hold on;
> K=L/W;


figure
V=10:15;
for N=1.5:0.5:3
S=(V.^2/2*9.81+S_t*(1-K-0.47*N))/(0.8*N-1+K);
plot(V,S);
hold on
end

Above computes the S vector for each point in the V vector w/o a loop
then plots it.

You'll probably want to add a color value to the plot since the colors
won't automagically cycle unless S is a column vector. Or, you could
create a 2D array and save the whole thing then plot since the sizes are
quite small...

V=[10:15]';
S=zeros(length(V)),4); % preallocate
i=0;
for N=1.5:0.5:3
i = i+1; % array column index
S(:,i)=(V.^2/2*9.81+S_t*(1-K-0.47*N))/(0.8*N-1+K);
end
plot(V,S);

And, of course, one could look at

doc meshgrid

to do the computation w/o any explicit loops at all...

--




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2013. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.