0% found this document useful (0 votes)
11 views3 pages

Matlab 3

This document outlines the process of generating a global stiffness matrix for a 2D frame using MATLAB. It includes definitions for material properties, node coordinates, and element connectivity, followed by a loop to assemble the global stiffness matrix. The final output displays the global stiffness matrix in a formatted manner.

Uploaded by

soudip27ce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Matlab 3

This document outlines the process of generating a global stiffness matrix for a 2D frame using MATLAB. It includes definitions for material properties, node coordinates, and element connectivity, followed by a loop to assemble the global stiffness matrix. The final output displays the global stiffness matrix in a formatted manner.

Uploaded by

soudip27ce
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

25/06/2025, 03:10 untitled

Contents
MATERIAL AND SECTION PROPERTIES

NODE COORDINATES (in feet)

ELEMENT CONNECTIVITY (startNode, endNode)

LOOP OVER ELEMENTS TO ASSEMBLE GLOBAL K


DISPLAY GLOBAL STIFFNESS MATRIX

% ================================
% Global Stiffness Matrix Generation for 2D Frame
% ================================

clc; clear;

MATERIAL AND SECTION PROPERTIES

E = 29000 * 1000; % psi


I = 44.237; % in^4
A = 23.04; % in^2

NODE COORDINATES (in feet)

node = [
1, 0, 0;
2, 0, 12;
3, 10, 0;
4, 10, 12
];

ELEMENT CONNECTIVITY (startNode, endNode)

elem = [
1, 1, 2;
2, 2, 4;
3, 4, 3
];

nn = size(node, 1); % number of nodes


ne = size(elem, 1); % number of elements
dof = 3; % degrees of freedom per node
tdof = nn * dof; % total degrees of freedom
K_global = zeros(tdof); % initialize global stiffness matrix

LOOP OVER ELEMENTS TO ASSEMBLE GLOBAL K

for e = 1:ne
n1 = elem(e,2); n2 = elem(e,3);
x1 = node(n1,2); y1 = node(n1,3);
x2 = node(n2,2); y2 = node(n2,3);

% Length and direction cosines


L = sqrt((x2-x1)^2 + (y2-y1)^2);
c = (x2-x1)/L;
s = (y2-y1)/L;
https://matlab.mathworks.com 1/3
25/06/2025, 03:10 untitled

% Element stiffness matrix in local coordinates


AE_L = A*E/L;
EI_L2 = E*I/L^2;
EI_L3 = E*I/L^3;

k_local = [ AE_L 0 0 -AE_L 0 0;


0 12*EI_L3 6*EI_L2 0 -12*EI_L3 6*EI_L2;
0 6*EI_L2 4*E*I/L 0 -6*EI_L2 2*E*I/L;
-AE_L 0 0 AE_L 0 0;
0 -12*EI_L3 -6*EI_L2 0 12*EI_L3 -6*EI_L2;
0 6*EI_L2 2*E*I/L 0 -6*EI_L2 4*E*I/L ];

% Transformation matrix T (6x6)


T = [ c s 0 0 0 0;
-s c 0 0 0 0;
0 0 1 0 0 0;
0 0 0 c s 0;
0 0 0 -s c 0;
0 0 0 0 0 1 ];

% Global stiffness matrix for this element


k_global = T' * k_local * T;

% Global DOF indices


index = [ (n1-1)*3+1, (n1-1)*3+2, (n1-1)*3+3, ...
(n2-1)*3+1, (n2-1)*3+2, (n2-1)*3+3 ];

% Assemble into global stiffness matrix


K_global(index,index) = K_global(index,index) + k_global;
end

DISPLAY GLOBAL STIFFNESS MATRIX

fprintf('\nGlobal Stiffness Matrix [K] (size: %d x %d):\n', tdof, tdof);


disp(K_global)

Global Stiffness Matrix [K] (size: 12 x 12):


1.0e+08 *

Columns 1 through 7

0.0891 0 -0.5345 -0.0891 0 -0.5345 0


0 0.5568 0 0 -0.5568 0 0
-0.5345 0 4.2762 0.5345 0 2.1381 0
-0.0891 0 0.5345 0.7572 0 0.5345 0
0 -0.5568 0 0 0.7107 0.7697 0
-0.5345 0 2.1381 0.5345 0.7697 9.4077 0
0 0 0 0 0 0 0.0891
0 0 0 0 0 0 0
0 0 0 0 0 0 -0.5345
0 0 0 -0.6682 0 0 -0.0891
0 0 0 0 -0.1539 -0.7697 0
0 0 0 0 0.7697 2.5657 -0.5345

Columns 8 through 12

0 0 0 0 0
0 0 0 0 0

https://matlab.mathworks.com 2/3
25/06/2025, 03:10 untitled
0 0 0 0 0
0 0 -0.6682 0 0
0 0 0 -0.1539 0.7697
0 0 0 -0.7697 2.5657
0 -0.5345 -0.0891 0 -0.5345
0.5568 0 0 -0.5568 0
0 4.2762 0.5345 0 2.1381
0 0.5345 0.7572 0 0.5345
-0.5568 0 0 0.7107 -0.7697
0 2.1381 0.5345 -0.7697 9.4077

Published with MATLAB® R2024b

https://matlab.mathworks.com 3/3

You might also like