for loop assistance selecting the correct values
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Eddy Ramirez
am 31 Mär. 2021
Kommentiert: Eddy Ramirez
am 2 Apr. 2021
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
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 31 Mär. 2021
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 Kommentare
Walter Roberson
am 2 Apr. 2021
At 90, cosd() is 0 and your expression becomes a constant, so solve() does not know what to do.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Environmental Models finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!