Plotting two lines

Im trying to plot an orbit and a line over the fixed point, but with the code i wrote, it only plots the orbit curve. what am i doing wrong?
function speed(v,h);
N=200/.01;
for n=[1:N-1];
v(n+1)=v(n)+.01/20*(-.5*v(n)+h);
end
plot(v);hold on
plot(h/.5,'r--')

 Accepted Answer

What size is h ?
If it is not a scalar then the v(n+1) calculation would return a vector (or array), which would not be storable in the scalar v(n+1)
If, though, h is a scalar, then plot(h,'r--') is asking to plot only a single point at (1,h) which might not be very visible. You could try increasing the MarkerSize to make it more visible. The "--" part of the line specification is not going to do you any good as "--" is only for connecting multiple points.
Perhaps what you want is
plot(N,h,'r--')
??

5 Comments

im supposed to plot 3 different lines, with v being 25 for all 3, and h being 0,10, and -20.
That doesn't make sense to me. If v is the constant 25 then because your formula involves only v and h, then h would have to be the value calculated. Or are you talking about the *initial* value for v that you pass in to the function?
If your h has 3 values simultaneously, then the "+h" part of your expression is going to be a vector of 3 values; you add the _scalar_ -v(n)/2 to that so the addition would give a vector of 3 values; you multiply that vector of 3 values by the scalar 0.01/20, so that would give you a vector of 3 values, you add the _scalar_ v(n) to that which would give you a vector of 3 values, and then you try to store that vector of values in the scalar location v(n+1).
and i tried your suggestion, no such luck.
I am trying to make a dashed red line, not individual points, and I am not getting anything
It is not simultaneous, i enter each orbit individually, so it would look like
speed(25,0)
speed(25,10)
speed(25,-20)
And it should plot three different curves, along with 3 dashed, red lines on the equilibrium speed.
Darn, I had posted complete source for you, but it got lost in the system update.
Anyhow, Try
plot([1 N],[h h] ./ .5,'r--')

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!