for loop to draw while loop ()
3 次查看(过去 30 天)
显示 更早的评论
%now P =700 ct number but I want to get same result for different P (600,700,900) in the same graph to make comparaision ,how can I plot it ?
clear all
close all
a=15;
b=60;
c=18.4;
Sy=1070;
P=700;
Py=501;
r=[a:0.01:b];
n=1;
%stress after loading
%plastic
while(r(n)<c)
%plastic region(ri<r<rp)
Sr(n)=-(Sy/2)*((P/Py)*(1-(a^2/r(n)^2))-log(r(n)^2/a^2));
So(n)=-(Sy/2)*((P/Py)*(1+(a^2/r(n)^2))-(2+log(r(n)^2/a^2)));
n=n+1;
end
%elastic
while (r(n)>=c)
%elastic region(rp<r<rp)
Sr(n)=-(Sy/2)*(((c^2/a^2)-(P/Py))*((a^2/r(n)^2)-(a^2/b^2)));
So(n)=(Sy/2)*(((c^2/a^2)-(P/Py))*((a^2/r(n)^2)+(a^2/b^2)));
n=n+1;
if n>length(r)
break
end
end
figure(1)
plot(r,Sr,'r',r,So,'b')
grid on
grid minor
3 个评论
David Hill
2020-4-16
Works for me.
a=15;
b=60;
c=[18.35,20.35,22.72];
Sy=1070;
P=[600,700,900];
Py=501;
r=[a:0.01:b];
%stress after loading
%plastic
for k=1:3
n=1;
while(r(n)<c(k))
%plastic region(ri<r<rp)
Sr(n,k)=-(Sy/2)*((P(k)/Py)*(1-(a^2/r(n)^2))-log(r(n)^2/a^2));
So(n,k)=-(Sy/2)*((P(k)/Py)*(1+(a^2/r(n)^2))-(2+log(r(n)^2/a^2)));
n=n+1;
end
%elastic
while (r(n)>=c(k))
%elastic region(rp<r<rp)
Sr(n,k)=-(Sy/2)*(((c(k)^2/a^2)-(P(k)/Py))*((a^2/r(n)^2)-(a^2/b^2)));
So(n,k)=(Sy/2)*(((c(k)^2/a^2)-(P(k)/Py))*((a^2/r(n)^2)+(a^2/b^2)));
n=n+1;
if n>length(r)
break
end
end
end
figure(1)
plot(r,Sr(:,1),r,Sr(:,2),r,Sr(:,3),r,So);%whatever colors ...
grid on
grid minor
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!