Plotting two lines

2 次查看(过去 30 天)
Abdullah Tamimi
Abdullah Tamimi 2011-10-25
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--')

采纳的回答

Walter Roberson
Walter Roberson 2011-10-25
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 个评论
Abdullah Tamimi
Abdullah Tamimi 2011-10-25
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.
Walter Roberson
Walter Roberson 2011-10-26
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--')

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Formatting and Annotation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by