When i run the blow code, the loop gets stuck on the underline line and it says that the indices on the left are not compatible with the indices on the right.

2 次查看(过去 30 天)
clc
clear all
sigma1=0.002;
sigma2=-0.003;
tau_12=0.004;
E1=181;
E2=10.3;
mu_12=0.28;
G12=7.17;
tetha=1:90;
for i=1:90
c(i)=cosd(tetha(i));
s(i)=sind(tetha(i));
Stress_12=[sigma1; sigma2; tau_12];
%S matrix calculation
S=[1/E1 -mu_12/E1 0;-mu_12/E1 1/E2 0;0 0 1/G12];
%Q matrix calculation
Q=inv(S);
%Strain Vector calculation
Strain_12=S*Stress_12;
%Transformation matrix calculation
T(i)=[c(i).^2 s(i).^2 2.*s(i).*c(i); s(i).^2 c(i).^2 -2.*s(i).*c(i); -s(i).*c(i) s(i).*c(i) (c(i).^2)-(s(i).^2)];
%Inverse of the transformation matrix
T_1(i)=inv(T(i));
end

回答(2 个)

KSSV
KSSV 2022-3-28
clc
clear all
sigma1=0.002;
sigma2=-0.003;
tau_12=0.004;
E1=181;
E2=10.3;
mu_12=0.28;
G12=7.17;
tetha=1:90;
c=cosd(tetha);
s=sind(tetha);
T = zeros(3,3,90) ;
for i=1:90
Stress_12=[sigma1; sigma2; tau_12];
%S matrix calculation
S=[1/E1 -mu_12/E1 0;-mu_12/E1 1/E2 0;0 0 1/G12];
%Q matrix calculation
Q=inv(S);
%Strain Vector calculation
Strain_12=S*Stress_12;
%Transformation matrix calculation
T(:,:,i)=[c(i).^2 s(i).^2 2.*s(i).*c(i); s(i).^2 c(i).^2 -2.*s(i).*c(i); -s(i).*c(i) s(i).*c(i) (c(i).^2)-(s(i).^2)];
end

Mathieu NOE
Mathieu NOE 2022-3-28
编辑:Mathieu NOE 2022-3-28
hello
try this (T is a 3 x 3 matrix not a scalar so it must be stored in a cell)
clc
clear all
sigma1=0.002;
sigma2=-0.003;
tau_12=0.004;
E1=181;
E2=10.3;
mu_12=0.28;
G12=7.17;
tetha=1:90;
% all this could be removed from the for loop (no need to repeat all the
% time the same code )
c=cosd(tetha);
s=sind(tetha);
Stress_12=[sigma1; sigma2; tau_12];
%S matrix calculation
S=[1/E1 -mu_12/E1 0;-mu_12/E1 1/E2 0;0 0 1/G12];
%Q matrix calculation
Q=inv(S);
%Strain Vector calculation
Strain_12=S*Stress_12;
for i=1:numel(tetha)
%Transformation matrix calculation
T{i}=[c(i)^2 s(i)^2 2*s(i)*c(i);
s(i)^2 c(i)^2 -2*s(i)*c(i);
-s(i)*c(i) s(i)*c(i) (c(i)^2)-(s(i)^2)];
%Inverse of the transformation matrix
T_1{i}=inv(T{i});
end

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by