# 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 visualizzazione (ultimi 30 giorni)
Mahmoud Chawki il 28 Mar 2022
Modificato: Mathieu NOE il 28 Mar 2022
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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (2)

KSSV il 28 Mar 2022
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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

Mathieu NOE il 28 Mar 2022
Modificato: Mathieu NOE il 28 Mar 2022
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
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!

Translated by