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.

조회 수: 1 (최근 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에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by