Application of For Next Statement?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
Michael Haderlein
le 3 Fév 2015
Modifié(e) : Michael Haderlein
le 3 Fév 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 commentaires
Michael Haderlein
le 4 Fév 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.
Voir également
Catégories
En savoir plus sur Stress and Strain dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!