Application of For Next Statement?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi Guys,
I am unable plot the graphs for the Stress Intensity Functions using For Next Loop. Hers is the script, can anybody explain me the fallacy for the code.
Code:
%------------Stress Plot---------------%
theta=0:0.1:360
n=length(theta)
m=1/3
for x=1:n
a=((0.25).*(1+cos(x)+(1.5).*(sin(x)).^2));
b=((0.25).*((1-(2.*m.^2)).*(1+cos(x))+(1.5.*(sin(x)).^2)));
end
figure
polar(theta,a,'b')
hold on
polar(theta,b,'r')
Thanks & Regards
0 Kommentare
Antworten (1)
Michael Haderlein
am 3 Feb. 2015
Bearbeitet: Michael Haderlein
am 3 Feb. 2015
Please make your code readable using the {}Code button on top of the edit window in future.
You are overwriting a in every loop iteration. Make it a(x) =... and it will work (the same with b).
Edit: I just realized you span theta from 0 to 360. sin and cos are radian based, so either span theta from 0 to 2*pi or use sind and cosd functions.
2 Kommentare
Michael Haderlein
am 4 Feb. 2015
Really, the code is barely readable without the code formatting. That's most likely the reason why I didn't see one important point in your code: You use x as argument of the trigonometric functions. It must be theta(x), of course. Anyway, you don't even need a loop:
a=((0.25).*(1+cos(theta)+(1.5).*(sin(theta)).^2));
will work for all theta at once.
Siehe auch
Kategorien
Mehr zu Stress and Strain finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!