Matrix dimensions must agree. error .

1 view (last 30 days)
%***** CALCULATE STRESS *****
stress1 = ones(1,6);
stress2 = ones(1,6);
direct = ones(1,6);
for i = 1:n_elem
lambda = [l_ij(i) m_ij(i) 0 0 0 0 ;...
-m_ij(i) l_ij(i) 0 0 0 0 ;...
0 0 1 0 0 0 ;...
0 0 0 l_ij(i) m_ij(i) 0 ;...
0 0 0 -m_ij(i) l_ij(i) 0 ;...
0 0 0 0 0 1];
B1Direct = [-1/l(i) 0 0 1/l(i) 0 0];
B1 = [-1/l(i) 6*t/l(i)^2 4*t/l(i) 1/l(i) (-6)*(t)/l(i)^2 (t)*(2)/l(i)];
B2 = [-1/l(i) -6*t/l(i)^2 -2*t/l(i) ...
1/l(i) 6*t/l(i)^2 -4*t/l(i)];
q = [u(connect(i,1)*3 - 2);...
u(connect(i,1)*3 - 1);
u(connect(i,1)*3);...
u(connect(i,2)*3 - 2);...
u(connect(i,2)*3 - 1);...
u(connect(i,2)*3)];
stress1(i) = (E(i)* B1) .* lambda .* q ;
stress2(i) = (E(i) * B2) .* lambda .* q ;
direct(i) = (E(i) * B1Direct) .* lambda .* q ;
end
%%Displays results as table format for the stresses node i of element
di = cell(1,n_elem); %Node in x Direction
for i=1:n_elem % Defines the number of the node
di{i} = ['elem' num2str(i)];
end
dirc = (reshape((di), size(di,1), (di))).'; %Concatenates node
stress_i_nodeMPa=table(dirc,round(stress1',4)); % Defines the values to show in table
stress_i_nodeMPa.Properties.VariableNames = {'Element','Stress'}; %Table column names
%%Displays results as table format for the stresses node j of element
sj = cell(1,n_elem); %Node in x Direction
for i=1:n_elem % Defines the number of the node
sj{i} = ['elem' num2str(i)];
end
stjc = (reshape((sj), size(sj,1), [])).'; %Concatenates node
stress_j_nodeMPa=table(stjc,round(stress2',4)); % Defines the values to show in table
stress_j_nodeMPa.Properties.VariableNames = {'Element','Stress'}; %Table column names
%%Displays results as table format for the direct stresses
di = cell(1,n_elem); %Node in x Direction
for i=1:n_elem % Defines the number of the node
di{i} = ['elem' num2str(i)];
end
dirc = (reshape((di), size(di,1), [])).'; %Concatenates node
DirStressMPa=table(dirc,round(direct',4)); % Defines the values to show in table
DirStressMPa.Properties.VariableNames = {'Element','Stress'}; %Table column names
  3 Comments
karthik velkuru venkata ramana murthy
Edited: Geoff Hayes on 20 Apr 2019
%***** MESH ***
X = [0 254 457.2 787.4 812.8 914.4 ]; % node x coordinates (mm)
Y = [0 381 0 381 304.8 0]; % node y coordinates (mm)
n_node = length (X); % number of nodes
n_elem = 7; % number of elements
connect = [1 2;2 3;1 3;2 4;3 5;4 5;5 6]; % node to element assignment
%***** MATERIAL & GEOMETRY PROPERTIES ***
l = sqrt((X(connect(:,2))-X(connect(:,1))).^2 +...
(Y(connect(:,2))-Y(connect(:,1))).^2); % element length (mm)
l_ij = (X(connect(:,2))-X(connect(:,1)))./l(1,:); % direction cosine cos(alfa)
m_ij = (Y(connect(:,2))-Y(connect(:,1)))./l(1,:); % direction cosine cos(beta)
D = [25.4 25.4 25.4 25.4 25.4 25.4 25.4];
d = [23.8 23.8 23.8 23.8 23.8 23.8 23.8];
A = pi*(D.^2-d.^2)/4; % cross-sectional area (mm^2) Q2
I = pi*(D.^4-d.^4)/64; % Izz moment of inertia (mm^4) t = 1.57 ; E = [200e3 200e3 200e3 200e3 200e3 200e3 200e3]; % Young's modulus of elasticity (N/mm^2) Q2
%***** BOUNDARY CONDITIONS ASSIGNMENT **
fixed_bc = [1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1]; % 1 fixed node % 0 free node
F = [0 0 0 0 -70.09 0 0 0 0 0 -12.09 0 0 0 0 0 0 0]; % 0 either unknown reaction force or % no force on node (N)
Geoff Hayes
Geoff Hayes on 20 Apr 2019
what is u? what is the full error message?

Sign in to comment.

Answers (0)

Categories

Find more on Stress and Strain in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!