for loop assistance selecting the correct values

1 回表示 (過去 30 日間)
Eddy Ramirez
Eddy Ramirez 2021 年 3 月 31 日
コメント済み: Eddy Ramirez 2021 年 4 月 2 日
Greetings,
I am runnig the for loop below and it seems that it works, but one issue that I am havng is that I think the for loop is taking the lenght (in this case taking 10) and solving for the matrix and equations. Is there a way for me to see it up where it reads each individual angle from 1 through 10. I tried to do "for i=1:10" and keeping everything else the same, but it does not work. I want the for loop to run angles 1 thorugh 10 through all the equations where I end up with 10 different results not just one(which is what I am getting since I am using "length") Thank you in advance for your assistance
theta=1:10;
m=cosd(theta);
n=sind(theta);
m2=m.^2;
n2=n.^2;
for i=1:length(theta)
T=[m2(i) n2(i) 2*m(i)*n(i);
n2(i) m2(i) -2*m(i)*n(i);
-m(i)*n(i) m(i)*n(i) m2(i)-n2(i)];
sigma1=sym('sigma_1');
sigma2=sym('sigma_2');
tau6=sym('tau_6');
stress=[sigma1; sigma2; tau6];
sigmax=0;
sigmay=0;
tau5=sym('taus');
stress_rotation=[sigmax; sigmay; tau5];
equation=stress==T*stress_rotation;
solution=solve(equation, stress);
sigma1_f=vpa(solution.sigma_1);
sigma2_f=vpa(solution.sigma_2);
tau6_f=vpa(solution.tau_6);
end

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 31 日
theta=1:10;
m=cosd(theta);
n=sind(theta);
m2=m.^2;
n2=n.^2;
for i=1:length(theta)
T=[m2(i) n2(i) 2*m(i)*n(i);
n2(i) m2(i) -2*m(i)*n(i);
-m(i)*n(i) m(i)*n(i) m2(i)-n2(i)];
sigma1=sym('sigma_1');
sigma2=sym('sigma_2');
tau6=sym('tau_6');
stress=[sigma1; sigma2; tau6];
sigmax=0;
sigmay=0;
tau5=sym('taus');
stress_rotation=[sigmax; sigmay; tau5];
equation=stress==T*stress_rotation;
solution=solve(equation, stress);
sigma1_f(i)=vpa(solution.sigma_1);
sigma2_f(i)=vpa(solution.sigma_2);
tau6_f(i)=vpa(solution.tau_6);
end
plot(theta, [sigma1_f(:), sigma2_f(:), tau6_f(:)]./tau5);
legend({'sigma1_f', 'sigma2_f', 'tau6_f'});
  6 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 2 日
At 90, cosd() is 0 and your expression becomes a constant, so solve() does not know what to do.
Eddy Ramirez
Eddy Ramirez 2021 年 4 月 2 日
makes sense which is why theta 0 wont work either... truly appreciate all your help and time!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by