for loop assistance selecting the correct values

4 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Stress and Strain 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by