0% found this document useful (0 votes)
9 views4 pages

TRBMFR Matlab

The document outlines a MATLAB script for structural analysis, allowing users to input material properties, geometry, and external forces to calculate nodal displacements and reactions at supports. The script includes the assembly of global stiffness matrices for members and applies boundary conditions to solve for displacements and reactions. It provides a systematic approach to analyze structures using finite element methods.

Uploaded by

bibekbhusal013
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)
9 views4 pages

TRBMFR Matlab

The document outlines a MATLAB script for structural analysis, allowing users to input material properties, geometry, and external forces to calculate nodal displacements and reactions at supports. The script includes the assembly of global stiffness matrices for members and applies boundary conditions to solve for displacements and reactions. It provides a systematic approach to analyze structures using finite element methods.

Uploaded by

bibekbhusal013
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/ 4

% Clear previous data % Clear previous data

clear; clear;
clc; clc;

% Geometry and material properties % Get material properties from user


E = 70e9; % Young's modulus in Pa E = input('Enter the value of Young''s modulus E (in Pa): ');
A = 2000e-6; % Cross-sectional area in m^2 A = input('Enter the cross-sectional area A (in m^2): ');
L1 = 4; % Length of member 1 in m
L2 = sqrt(3^2 + 4^2); % Length of member 2 in m % Get geometry from user
L1 = input('Enter the length of member 1 (in m): ');
% Coordinates of joints L2 = input('Enter the length of member 2 (in m): ');
coords = [0, 0; 4, 0; 0, 3]; % [x, y]
% Get coordinates of joints from user
% Connectivity matrix coords = input('Enter the coordinates of the joints as a matrix [x1
connectivity = [1 2; 2 3]; y1; x2 y2; x3 y3]: ');
% Get connectivity matrix from user
% Number of joints and members connectivity = input('Enter the connectivity matrix as a matrix
numJoints = size(coords, 1); [n1_start n1_end; n2_start n2_end]: ');
numMembers = size(connectivity, 1); % Calculate lengths if needed
% L1 = sqrt((coords(2,1)-coords(1,1))^2 + (coords(2,2)-coords(1,2))^2);
% Stiffness matrices for each member in local coordinates % L2 = sqrt((coords(3,1)-coords(2,1))^2 + (coords(3,2)-coords(2,2))^2);
k1 = (E * A / L1) * [1 -1; -1 1];
k2 = (E * A / L2) * [1 -1; -1 1]; % Define number of joints and members
numJoints = size(coords, 1); % Number of rows in coords
% Transformation matrices for each member numMembers = size(connectivity, 1); % Number of rows in connectivity
theta1 = 0; % angle for member 1
theta2 = atan2(3, 4); % angle for member 2 % Define stiffness matrices for each member in local coordinates
k1 = (E * A / L1) * [1 -1; -1 1];
T1 = [cos(theta1) sin(theta1) 0 0; 0 0 cos(theta1) sin(theta1)]; k2 = (E * A / L2) * [1 -1; -1 1];
T2 = [cos(theta2) sin(theta2) 0 0; 0 0 cos(theta2) sin(theta2)];
% Transformation matrices for each member
% Global stiffness matrices for each member theta1 = 0; % angle for member 1
k1_global = T1' * k1 * T1; theta2 = atan2(coords(3,2) - coords(2,2), coords(3,1) - coords(2,1));
k2_global = T2' * k2 * T2; % angle for member 2
T1 = [cos(theta1) sin(theta1) 0 0; 0 0 cos(theta1) sin(theta1)];
% Global stiffness matrix assembly T2 = [cos(theta2) sin(theta2) 0 0; 0 0 cos(theta2) sin(theta2)];
K = zeros(2*numJoints);
K(1:4, 1:4) = K(1:4, 1:4) + k1_global; % Global stiffness matrices for each member
K(3:6, 3:6) = K(3:6, 3:6) + k2_global; k1_global = T1' * k1 * T1;
k2_global = T2' * k2 * T2;
% Apply boundary conditions
% Known displacements (fixed supports at joints 1 and 3) % Global stiffness matrix assembly
fixedDof = [1 2 5 6]; K = zeros(2*numJoints);
activeDof = setdiff(1:2*numJoints, fixedDof); K(1:4, 1:4) = K(1:4, 1:4) + k1_global;
K(3:6, 3:6) = K(3:6, 3:6) + k2_global;
% External forces
F = zeros(2*numJoints, 1); % Apply boundary conditions
F(4) = -75e3; % 75 kN load at joint 2 in y-direction % Known displacements (fixed supports at joints 1 and 3)
fixedDof = [1 2 5 6];
% Solve for displacements activeDof = setdiff(1:2*numJoints, fixedDof);
u = zeros(2*numJoints, 1);
u(activeDof) = K(activeDof, activeDof) \ F(activeDof); % Define external forces
F = zeros(2*numJoints, 1);
% Calculate reactions F(4) = input('Enter the external force at joint 2 in y-
R = K * u - F; direction (in N): ');
% Solve for displacements
% Display results u = zeros(2*numJoints, 1);
disp('Nodal displacements (in meters):'); u(activeDof) = K(activeDof, activeDof) \ F(activeDof);
disp(reshape(u, 2, [])');
% Calculate reactions
disp('Reactions at supports (in N):'); R = K * u - F;
disp(reshape(R(fixedDof), 2, [])');
% Display results
% Member end forces in local coordinates disp('Nodal displacements (in meters):');
F1_local = k1 * T1 * u([1 2 3 4]); disp(reshape(u, 2, [])');
F2_local = k2 * T2 * u([3 4 5 6]);
disp('Reactions at supports (in N):');
% Display member end forces disp(reshape(R(fixedDof), 2, [])');
disp('Member end forces in local coordinates (in N):');
disp('Member 1:'); % Member end forces in local coordinates
disp(F1_local); F1_local = k1 * T1 * u([1 2 3 4]);
disp('Member 2:'); F2_local = k2 * T2 * u([3 4 5 6]);
disp(F2_local);
% Display member end forces
disp('Member end forces in local coordinates (in N):');
disp('Member 1:');
disp(F1_local);
disp('Member 2:');
disp(F2_local);

% Clear previous data % Clear previous data


clear; clear;
clc; clc;

% Get material properties from user % Number of segments


E = input('Enter the value of Young''s modulus E (in Pa): '); numSegments = 2; % For the given problem
I = input('Enter the moment of inertia I (in m^4): ');
% Preallocate arrays for material properties, lengths, and stiffness matrices
% Get geometry from user E = zeros(1, numSegments);
L1 = input('Enter the length of segment 1 (in m): '); I = zeros(1, numSegments);
L2 = input('Enter the length of segment 2 (in m): '); L = zeros(1, numSegments);
K = zeros(2*numSegments+2, 2*numSegments+2);
% Define stiffness matrices for each segment
k1 = (E * I / L1^3) * [12 6*L1 -12 6*L1; % Loop to get user input for each segment
6*L1 4*L1^2 -6*L1 2*L1^2; for i = 1:numSegments
-12 -6*L1 12 -6*L1; fprintf('For segment %d:\n', i);
6*L1 2*L1^2 -6*L1 4*L1^2]; E(i) = input('Enter the value of Young''s modulus E (in Pa): ');
I(i) = input('Enter the moment of inertia I (in m^4): ');
k2 = (E * I / L2^3) * [12 6*L2 -12 6*L2; L(i) = input('Enter the length of the segment (in m): ');
6*L2 4*L2^2 -6*L2 2*L2^2;
-12 -6*L2 12 -6*L2; % Calculate local stiffness matrix for the segment
6*L2 2*L2^2 -6*L2 4*L2^2]; k = (E(i) * I(i) / L(i)^3) * [12 6*L(i) -12 6*L(i);
6*L(i) 4*L(i)^2 -6*L(i) 2*L(i)^2;
% Global stiffness matrix assembly -12 -6*L(i) 12 -6*L(i);
K = zeros(6, 6); 6*L(i) 2*L(i)^2 -6*L(i) 4*L(i)^2];
K(1:4, 1:4) = K(1:4, 1:4) + k1;
K(3:6, 3:6) = K(3:6, 3:6) + k2; % Assemble global stiffness matrix
K(2*i-1:2*i+2, 2*i-1:2*i+2) = K(2*i-1:2*i+2, 2*i-1:2*i+2) + k;
% Apply boundary conditions end
% Known displacements (fixed support at joint 1 and roller at joint 2)
fixedDof = [1 2]; % Apply boundary conditions
rollerDof = [3]; % Known displacements (fixed support at joint 1 and roller at joint 2)
activeDof = setdiff(1:6, [fixedDof rollerDof]); fixedDof = [1 2];
rollerDof = [3];
% Define external forces activeDof = setdiff(1:2*numSegments+2, [fixedDof rollerDof]);
F = zeros(6, 1);
F(6) = input('Enter the external force at joint 3 in y-direction (in N): '); % Define external forces
F = zeros(2*numSegments+2, 1);
% Solve for displacements F(2*numSegments+2) = input('Enter the external force at joint 3 in y-direction (in N): ');
u = zeros(6, 1);
u(activeDof) = K(activeDof, activeDof) \ F(activeDof); % Solve for displacements
u = zeros(2*numSegments+2, 1);
% Calculate reactions u(activeDof) = K(activeDof, activeDof) \ F(activeDof);
R = K * u - F;
% Calculate reactions
% Display results R = K * u - F;
disp('Nodal displacements (in meters):');
disp(reshape(u, 2, [])'); % Display results
disp('Nodal displacements (in meters):');
disp('Reactions at supports (in N):'); disp(reshape(u, 2, [])');
disp(reshape(R([fixedDof, rollerDof]), 2, [])');
disp('Reactions at supports (in N):');
disp(reshape(R([fixedDof, rollerDof]), 2, [])');

% Clear previous data


clear;
clc;

% Material properties
E = 200e9; % Young's modulus in Pa
A = 16000e-6; % Cross-sectional area in m^2
I = 1186e-6; % Moment of inertia in m^4

% Geometry
L1 = 16; % Length of member 1 in m
L2 = 7; % Length of member 2 in m

% Load
w = 20e3; % Distributed load in N/m

% Number of degrees of freedom


numDof = 9;

% Global stiffness matrix


K = zeros(numDof, numDof);

% Local stiffness matrix for member 1 (vertical column)


k1 = (E*I / L1^3) * [12 6*L1 -12 6*L1;
6*L1 4*L1^2 -6*L1 2*L1^2;
-12 -6*L1 12 -6*L1;
6*L1 2*L1^2 -6*L1 4*L1^2];

% Local stiffness matrix for member 2 (horizontal beam with distributed load)
k2 = (E*I / L2^3) * [12 6*L2 -12 6*L2;
6*L2 4*L2^2 -6*L2 2*L2^2;
-12 -6*L2 12 -6*L2;
6*L2 2*L2^2 -6*L2 4*L2^2];

% Transformation matrix for member 2 (rotated)


theta = atan(7/24); % Angle of member 2
c = cos(theta);
s = sin(theta);
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];

k2_transformed = T' * k2 * T;

% Assemble global stiffness matrix


K([1 2 7 8], [1 2 7 8]) = K([1 2 7 8], [1 2 7 8]) + k1;
K([3 4 7 8 9 10], [3 4 7 8 9 10]) = K([3 4 7 8 9 10], [3 4 7 8 9 10]) + k2_transformed;

% Load vector (only the horizontal beam has distributed load)


F = zeros(numDof, 1);
F(7) = -w * L2 / 2;
F(9) = -w * L2;

% Boundary conditions (fixed support at node 1, roller at node 2)


fixedDof = [1 2 3]; % DOFs at node 1
rollerDof = [7 8]; % DOFs at node 2
activeDof = setdiff(1:numDof, [fixedDof, rollerDof]);
% Solve for displacements
u = zeros(numDof, 1);
u(activeDof) = K(activeDof, activeDof) \ F(activeDof);

% Calculate reactions
R = K * u - F;

% Display results
disp('Nodal displacements (in meters):');
disp(u);

disp('Reactions at supports (in N):');


disp(R([fixedDof, rollerDof]));

You might also like