Error in sum of matrixes

1 visualizzazione (ultimi 30 giorni)
Marcelo Boldt
Marcelo Boldt il 14 Lug 2020
Commentato: Marcelo Boldt il 15 Lug 2020
Dear Community,
I need to create a script where I obtain a matrix as an output. In addition, such matrix is a resultant matrix of the sum of 8 other matrixes. Unfortunately when I create the for loop it saves only the 8th matrix in the variable that I created to fulfill such requirement. Could you pelase help me?
clc
close all
clear all
m = 5;
Z = randi(20,1,10);
n = size(Z,2);
Z_out = [Z;zeros(m-1,n)];
for ii=2:m
Z_out(ii,:) = Z_out(ii-1,:) + randi(5,1,n);
end
%% Copiando el sistema
Nplies = 8;
thetadt = [90; -45; 45; 0; 0; 45; -45; 90];
t = 0.125; %SI unit, milimeters
h = Nplies*t;
% Ply engineering properties (UD-Laminat)
E1 = 240000; % N/mm^2
nu12 = .3133 ;
E2 = 7500 ; % N/mm^2
G12 = 5150 ; % N/mm^2
nu21 = .3133 ; %nu12 * E2 / E1
a1 = -0.38e-7 ; % coefficients of thermal expansion [1/°C]
a2 = 1e-5 ;
deltaT = 0;
% Q matrix (material coordinates)- reduced stiffness matrix
denom = 1 - nu12 * nu21 ;
Q11 = E1 / denom ; %reduced stiffness coefficients
Q12 = nu12 * E1 / denom ;
Q21 = nu12 * E2 / denom ;%reduced stiffness coefficients
Q22 = E2 / denom ; %reduced stiffness coefficients
Q66 = G12 ; %reduced stiffness coefficients
m = 3;
Ai = [1,0,0;0,1,0;0,0,1];
Aii = zeros(3,3);
Qbari = zeros(3,3);
R = [1,0,0;0,1,0;0,0,2];
Q = [ E1/denom nu12*E1/denom 0; nu12* E2/denom E2/denom 0; 0 0 G12]; %Reduced stiffness matrix
AA=[];
for i = 1:Nplies
theta = thetadt(i) * pi / 180;% ply i angle in radians, from bottom
c = cos(theta);
s = sin(theta);
T = [ c^2 s^2 -2*c*s; s^2 c^2 2*c*s; c*s -c*s (c^2 - s^2)];
T_inv = [c^2 s^2 c*s; s^2 c^2 -c*s; -2*c*s 2*c*s (c^2 - s^2)];
Qbar = Qbari + T * Q * T_inv %transformed reduced stiffness matrix
A{i,1,1} = Aii + Qbar*t
end
Af = A{1,1,1} + A{2,1,1} + A{3,1,1} + A{4,1,1} + A{5,1,1} + A{6,1,1} + A{7,1,1} + A{8,1,1}
%% another approach
res=0;
for k=1:5
M=rand(4);
res=bsxfun(@plus,res,M);
end
%%
%if ii<2
% A=0;
% else
%transformed reduced stiffness matrix
% A = Aii + Qbar*(ii-1)*t
% end
  4 Commenti
Image Analyst
Image Analyst il 14 Lug 2020
Did you try the answer below? And why didn't you format your code like I suggested?
Marcelo Boldt
Marcelo Boldt il 14 Lug 2020
Yes I tried and it works but not as planed. Here are the modifications/editing

Accedi per commentare.

Risposte (1)

Rafael Hernandez-Walls
Rafael Hernandez-Walls il 14 Lug 2020
try this
Nplies = 8;
thetadt = [90; -45; 45; 0; 0; 45; -45; 90];
t = 0.125; %SI unit, milimeters
h = Nplies*t;
% Ply engineering properties (UD-Laminat)
E1 = 240000; % N/mm^2
nu12 = .3133 ;
E2 = 7500 ; % N/mm^2
G12 = 5150 ; % N/mm^2
nu21 = .3133 ; %nu12 * E2 / E1
a1 = -0.38e-7 ; % coefficients of thermal expansion [1/°C]
a2 = 1e-5 ;
deltaT = 0;
% Q matrix (material coordinates)- reduced stiffness matrix
denom = 1 - nu12 * nu21 ;
Q11 = E1 / denom ; %reduced stiffness coefficients
Q12 = nu12 * E1 / denom ;
Q21 = nu12 * E2 / denom ;%reduced stiffness coefficients
Q22 = E2 / denom ; %reduced stiffness coefficients
Q66 = G12 ; %reduced stiffness coefficients
m = 3;
Ai = [1,0,0;0,1,0;0,0,1];
Aii = zeros(3,3);
R = [1,0,0;0,1,0;0,0,2];
Q = [ E1/denom nu12*E1/denom 0; nu12* E2/denom E2/denom 0; 0 0 G12]; %Reduced stiffness matrix
AA=[];
for i = 1:Nplies
theta = thetadt(i) * pi / 180;% ply i angle in radians, from bottom
c = cos(theta)
s = sin(theta)
T = [ c^2 s^2 -2*c*s; s^2 c^2 2*c*s; c*s -c*s (c^2 - s^2)]
T_inv = [c^2 s^2 c*s; s^2 c^2 -c*s; -2*c*s 2*c*s (c^2 - s^2)]
Qbar = T * Q * T_inv;
for ii=2
%transformed reduced stiffness matrix
A = Aii + Qbar*(ii-1)*t;
AA = [AA; sum(A,1)]
end
end
  1 Commento
Marcelo Boldt
Marcelo Boldt il 15 Lug 2020
Hi, thanks for your help. I tried the problem but unfortunately I cant obtain what I need to. the matrix A is what I am trying to calculate. This matrix is a 3x3 but the problem that I am facing is that after my most recent update I am getting a 8x1 array where in each row I have a 3x3 matrix inside and I cant usa that data for further plots or anything like that.
Nplies = 8; % number of plies
thetadt = [90; -45; 45; 0; 0; 45; -45; 90];
t = 0.125; % thickness [SI unit], milimeters
h = Nplies*t;
% Ply engineering properties (UD-Laminat)
E1 = 131900; % N/mm^2
nu12 = .3 ;
E2 = 9700 ; % N/mm^2
G12 = 5200 ; % N/mm^2
nu21 = .022 ; %nu12 * E2 / E1
a1 = 4e-7 ; % coefficients of thermal expansion [1/°C]
a2 = 3e-5 ; % coefficients of thermal expansion [1/°C]
a = [a1 a2 0]'; % coefficients of thermal expansion vector [1/°C]
deltaT = 30;
% Q matrix (material coordinates)- reduced stiffness matrix
denom = 1 - nu12 * nu21 ;
Q11 = E1 / denom ; %reduced stiffness coefficients
Q12 = nu21 * E1 / denom ;
Q21 = nu12 * E2 / denom ;%reduced stiffness coefficients
Q22 = E2 / denom ; %reduced stiffness coefficients
Q66 = G12 ; %reduced stiffness coefficients
% Classical laminar theory
% m = 3; To use it in case I need HIBEF
Ai = zeros(3,3);
Bi = zeros(3,3);
Di = zeros(3,3);
NTi = zeros(3,1);
MTi = zeros(3,1);
Qbari = zeros(3,3);
NT_plot =[];
nt_plot = zeros(3,1);
R = [1,0,0;0,1,0;0,0,2];
Q = [ E1/denom nu21*E1/denom 0; nu12* E2/denom E2/denom 0; 0 0 G12]; %Reduced stiffness matrix
for i = 1:Nplies
zbar(i) = -(h + t)/2 + i*t;
theta = thetadt(i) * pi / 180;% ply i angle in radians, from bottom
c = cos(theta);
s = sin(theta);
T = [ c^2 s^2 -2*c*s; s^2 c^2 2*c*s; c*s -c*s (c^2 - s^2)];
T_inv = [c^2 s^2 c*s; s^2 c^2 -c*s; -2*c*s 2*c*s (c^2 - s^2)];
Qbar = T * Q * T_inv; %transformed reduced stiffness matrix
Qbar2 {i,1,1} = Qbari + T * Q * T_inv;
A{i,1} = Ai + Qbar*t;
end

Accedi per commentare.

Categorie

Scopri di più su Spline Postprocessing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by