for loop assistance selecting the correct values

조회 수: 2 (최근 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 CenterFile Exchange에서 Environmental Models에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by