Plotting for loop values

1 次查看(过去 30 天)
Ashmika Gupta
Ashmika Gupta 2021-3-11
Hello! I am trying to plot values using a for loop but everytime I run the code I get a figure with nothing on it except for axis values. I am not sure how to fix this.
EA=30000;
alpha=30;
beta=30;
gamma=180-(alpha+beta);
a=20;
n=6;
L_ab=a;
L_bc=(a*sind(alpha))/(sind(beta));
L_ac=(a*sind(alpha+beta))/(sind(beta));
for h = 0.1:0.1:1
syms r phi
U=((n*EA)/2)*(L_ab*((2*(r/L_ab)*sin(pi/n)-1)^2)+L_bc*(((sind(beta)/sind(alpha))*sqrt(((h/L_ab)^2)...
-(2*((r/L_ab)^2)*cos(phi))+2*((r/L_ab)^2)))-1)^2+L_ac*((sind(beta)/sind(alpha+beta))*sqrt(((h/L_ab)^2)...
-(2*((r/L_ab)^2)*cos(phi+(2*pi/n)))+(2*((r/L_ab)^2)))-1)^2);
assume(phi>=0 & phi<=2*pi)
assumeAlso(r<=2)
assumeAlso(r,'positive')
eqns=[diff(U,r)==0,diff(U,phi)==0]
sol=vpasolve(eqns,[r,phi])
sol1=sol.r
sol2=sol.phi
plot(h,sol1,'r'); hold on
plot(h,sol2,'b')
end

回答(1 个)

David Hill
David Hill 2021-3-11
编辑:David Hill 2021-3-11
Try indexing
h=.1:.1:1;
for H = 1:length(h)
syms r phi
U=((n*EA)/2)*(L_ab*((2*(r/L_ab)*sin(pi/n)-1)^2)+L_bc*(((sind(beta)/sind(alpha))*sqrt(((h(H)/L_ab)^2)...
-(2*((r/L_ab)^2)*cos(phi))+2*((r/L_ab)^2)))-1)^2+L_ac*((sind(beta)/sind(alpha+beta))*sqrt(((h(H)/L_ab)^2)...
-(2*((r/L_ab)^2)*cos(phi+(2*pi/n)))+(2*((r/L_ab)^2)))-1)^2);
assume(phi>=0 & phi<=2*pi)
assumeAlso(r<=2)
assumeAlso(r,'positive')
eqns=[diff(U,r)==0,diff(U,phi)==0]
sol=vpasolve(eqns,[r,phi])
sol1(H)=sol.r
sol2(H)=sol.phi
end
plot(h,sol1,'r',h,sol2,'b');
  3 个评论
David Hill
David Hill 2021-3-11
Are you getting a solution?
sol=vpasolve(eqns,[r,phi]);
Is the above line passing?
Ashmika Gupta
Ashmika Gupta 2021-3-12
No, it is not. I am not sure why as h is defined above.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by