for loop to draw while loop ()

1 次查看(过去 30 天)
Mohamad Mourad
Mohamad Mourad 2020-4-5
评论: David Hill 2020-4-16
%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 个评论
Mohamad Mourad
Mohamad Mourad 2020-4-15
Hello David fistly thanks you for your answers I have just a last question if c=[18.35,20.35,22.72]; like p
this mean for each p we have different c
Sr(n,k)=(-Sy/sqrt(3))*((c(k)^2/a^2)-(P(k)/Py))*((a^2/r(n)^2)-(a^2/b^2));
So(n,k)=(Sy/sqrt(3))*((c(k)^2/a^2)-(P(k)/Py))*((a^2/r(n)^2)+(a^2/b^2));
i tried to write it like that but this make error in matrix
should i make new counter for c also ?
David Hill
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 个)

类别

Help CenterFile Exchange 中查找有关 Polymers 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by