필터 지우기
필터 지우기

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