Clear Filters
Clear Filters

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 view (last 30 days)
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

Answers (2)

KSSV
KSSV on 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

Mathieu NOE
Mathieu NOE on 28 Mar 2022
Edited: Mathieu NOE on 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

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!