MATLAB: What’s wrong with the code for this plot

graphlinspaceplotpolynomialratio

I'm trying to plot drag D against mass M for various values of the ratio R between the inertia I and mass M, i.e. R=I/M but when I plot this I only get the R=0.5 line. How do I fix this?
M=linspace(0,1,50);
I=linspace(0,1,50);
A=0.7;
g=10;
for R=[0.02, 0.1, 0.2, 0.5];
R=I/M;
s=(A-0.5)*M.*g-(A^2)/4;
theta=s./(2*M.*(A-0.5)^2+2*I+(A^2-A+1/3)/2);
D=(A.^2-A+1/3).*theta+0.5*A.^2;
plot(M,D)
axis([0,1,-1,1])
xlabel('M')
ylabel('D')
hold all
grid on
end
legend('R=0.02','R=0.1','R=0.2','R=0.5')

Best Answer

One possible problem is that R isn’t used to calculate D (or anything else), and never changes because:
R=I/M;
in every iteration of the loop. D doesn’t change either.