Plotting for loop values
1 回表示 (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
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
2021 年 3 月 11 日
Are you getting a solution?
sol=vpasolve(eqns,[r,phi]);
Is the above line passing?
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!