Trouble plotting multiple graphs

1 次查看(过去 30 天)
Josie
Josie 2014-8-20
编辑: Patrik Ek 2014-8-20
I trying to plot multiple graphs of mass vs drag. I know the equation is correct but the plot's shouldn't be coming out with negative drag. Is there something wrong with the code?
M=linspace(0,1,100);
g=10;
for A=0.1:0.1:0.9
s=(A-0.5)*M.*g-(A^2)/4;
theta=s./(2*M.*(A-0.5)^2+2*M+(A^2-A+1/3)/2);
D=(-A.^2+A-1/3).*theta-0.5*A.^2;
plot(M,D)
axis([0,1,-2,2])
hold all
end
legend('A=0.1','A=0.2','A=0.3','A=0.4','A=0.5','A=0.6','A=0.7','A=0.8','A=0.9')
  1 个评论
Patrik Ek
Patrik Ek 2014-8-20
编辑:Patrik Ek 2014-8-20
The equation for D is quite simple assuming theta is an independent variable, which it of course not is, since it is calculated. Still it can be treated as such to calculate D(theta), since D does not rely on M except for the dependence in theta. You can look at equation D as a function of theta and find out how D varies with theta.
This can be done by creating a vector theta = -2*pi:0.01:2*pi and use it as input to D. By plotting
plot(theta,D);
you will then see how D depends on theta for different values of A. With the help of these graphs you can see if the result is reasonable.

请先登录,再进行评论。

回答(2 个)

Adam
Adam 2014-8-20
Well, the plots are negative because the result data is.
(-A.^2+A-1/3).*theta
ranges from -0.3785 to 0.4050.
0.5*A.^2
is 0.4050. So when you subtract this from the above the highest value you get will be 0, everything else will be negative

Iain
Iain 2014-8-20
Theres something wrong with your sums.
By hand, calculate D, for A = 0.1 and M = 0 & 100. You ought to see that D is negative.

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by