for loop assistance selecting the correct values

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

 Respuesta aceptada

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 comentarios

Walter,
THANK YOU SO MUCH!!!! Sorry to bother you again, I moved some equations inside the for loop and they are working as I wanted to, but do you know why I not getting an answer when I solve my equations? I even tried to changed it from "solve" to "double(vpasolve())"
clear all
close all
clc
F1t=1140/1000;
F1c=620/1000;
E1=41;
F2t=39/1000;
F2c=128/1000;
E2=10.4;
F6=89/1000;
G12=4.3;
v12=0.28;
v21=0.06;
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);
%%%computing the values for longitudinal tensile strain, transverse
%%%compressive strain, and in-plane shear strain
e1t_u(i)=F1t/E1;
e2c_u(i)=-(F2c/E2);
gamma6_u(i)=F6/G12;
%%% MAX STRAIN THEORY
e1=(sigma1_f./E1)-v21.*(sigma2_f./E2);
e2=(sigma2_f./E2)-v12.*(sigma1_f./E1);
gamma6=tau6_f./G12;
%%%Comparing Longitudinal tensile strain e1 w/ failure condition
e1vse1t_u=e1==e1t_u;
e1vse1t_uf=solve(e1vse1t_u);
%%%Comparing transverse compression strain e2 w/ failure condition
e2vse2t_u=e2==e2c_u;
e2vse2t_uf=solve(e2vse2t_u);
%%%Selecting Min. Value of strenth value from longitudinal tensile stregth,
%%%transverse compressive strength, and shear strenghth for the lamina
e1vse2min=min(e1vse1t_uf,e2vse2t_uf);
end
Eddy Ramirez
Eddy Ramirez el 1 de Abr. de 2021
When I do "keyboard" to enter the debugging, If I look up "e2vse2t_u" it shows all the equations as it should, but the solving area is the one that is giving me errors. I also, tried to use vpasolve and still get 0-1
F1t=1140/1000;
F1c=620/1000;
E1=41;
F2t=39/1000;
F2c=128/1000;
E2=10.4;
F6=89/1000;
G12=4.3;
v12=0.28;
v21=0.06;
theta=1:10;
ntheta = length(theta);
m=cosd(theta);
n=sind(theta);
m2=m.^2;
n2=n.^2;
sigma1_f = zeros(1,ntheta,'sym');
sigma2_f = zeros(1,ntheta,'sym');
tau6_f = zeros(1,ntheta,'sym');
e1t_u = zeros(1,ntheta);
e2c_u = zeros(1,ntheta);
gamma6_u = zeros(1,ntheta);
e1vse2min = zeros(1,ntheta);
for i=1:ntheta
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);
%%%computing the values for longitudinal tensile strain, transverse
%%%compressive strain, and in-plane shear strain
e1t_u(i)=F1t/E1;
e2c_u(i)=-(F2c/E2);
gamma6_u(i)=F6/G12;
%%% MAX STRAIN THEORY
e1=(sigma1_f(i)./E1)-v21.*(sigma2_f(i)./E2);
e2=(sigma2_f(i)./E2)-v12.*(sigma1_f(i)./E1);
gamma6=tau6_f(i)./G12;
%%%Comparing Longitudinal tensile strain e1 w/ failure condition
e1vse1t_u=e1==e1t_u(i);
e1vse1t_uf=solve(e1vse1t_u);
%%%Comparing transverse compression strain e2 w/ failure condition
e2vse2t_u = e2==e2c_u(i);
e2vse2t_uf=solve(e2vse2t_u);
%%%Selecting Min. Value of strenth value from longitudinal tensile stregth,
%%%transverse compressive strength, and shear strenghth for the lamina
e1vse2min(i) = min(e1vse1t_uf,e2vse2t_uf);
end
I am sorry to keep bothering you here, everything works as I was hoping for so thank you so much. When i increase the angles to 90 I get the following error
Error using sym/solve (line 266)
Specify the variable to solve for.
Any idea what is triggering this? I removed the entry saved it typed it back in and it did not work. It might be the 90? i tried it with 80 and it works. Also, any ideas on how to set it where i can do theta from 0-90?thank you again for all your help and I apologize for all the questions
F1t=1140/1000;
F1c=620/1000;
E1=41;
F2t=39/1000;
F2c=128/1000;
E2=10.4;
F6=89/1000;
G12=4.3;
v12=0.28;
v21=0.06;
theta=1:90;
ntheta = length(theta);
m=cosd(theta);
n=sind(theta);
m2=m.^2;
n2=n.^2;
sigma1_f = zeros(1,ntheta,'sym');
sigma2_f = zeros(1,ntheta,'sym');
tau6_f = zeros(1,ntheta,'sym');
e1t_u = zeros(1,ntheta);
e2c_u = zeros(1,ntheta);
gamma6_u = zeros(1,ntheta);
e1vse2min = zeros(1,ntheta);
for i=1:ntheta
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);
%%%computing the values for longitudinal tensile strain, transverse
%%%compressive strain, and in-plane shear strain
e1t_u(i)=F1t/E1;
e2c_u(i)=-(F2c/E2);
gamma6_u(i)=F6/G12;
%%% MAX STRAIN THEORY
e1=(sigma1_f(i)./E1)-v21.*(sigma2_f(i)./E2);
e2=(sigma2_f(i)./E2)-v12.*(sigma1_f(i)./E1);
gamma6=tau6_f(i)./G12;
%%%Comparing Longitudinal tensile strain e1 w/ failure condition
e1vse1t_u=e1==e1t_u(i);
e1vse1t_uf=solve(e1vse1t_u);
%%%Comparing transverse compression strain e2 w/ failure condition
e2vse2t_u = e2==e2c_u(i);
e2vse2t_uf=solve(e2vse2t_u);
%%%Selecting Min. Value of strenth value from longitudinal tensile stregth,
%%%transverse compressive strength, and shear strenghth for the lamina
e1vse2min(i) = min(e1vse1t_uf,e2vse2t_uf);
end
At 90, cosd() is 0 and your expression becomes a constant, so solve() does not know what to do.
Eddy Ramirez
Eddy Ramirez el 2 de Abr. de 2021
makes sense which is why theta 0 wont work either... truly appreciate all your help and time!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Classical Mechanics en Centro de ayuda y File Exchange.

Preguntada:

el 31 de Mzo. de 2021

Comentada:

el 2 de Abr. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by