Problem
Problem
MATLAB
%% Problem 1 Beam Analysis
% -----------------------------
% ASSEMBLE ELEMENT MATRICES % SOLVE SYSTEM OF EQUATIONS
% ----------------------------- % -----------------------------
% -----------------------------
for e = 1:2 U = zeros(numDOF, 1);
% MATERIAL & SECTION PROPERTIES
x1 = nodes(elements(e,1)); U(freeDOFs) = K(freeDOFs, freeDOFs) \ F(freeDOFs);
% -----------------------------
x2 = nodes(elements(e,2));
= 200e9; % Young's Modulus [Pa]
Le = x2 - x1;
= 4e6*1e-12; % Moment of Inertia [m^4] % Display slope results
= 0.2; % Beam thickness [m] fprintf('Slope at Node 2 = %.6e rad\n', U(4));
% Local stiffness matrix for Euler-Bernoulli beam
= h / 2; % Distance to top fiber [m] fprintf('Slope at Node 3 = %.6e rad\n', U(6));
ke = E*I/Le^3 * [12, 6*Le, -12, 6*Le;
6*Le, 4*Le^2, -6*Le, 2*Le^2;
-12, -6*Le, 12, -6*Le; % -----------------------------
% -----------------------------
6*Le, 2*Le^2, -6*Le, 4*Le^2]; % COMPUTE STRESS AT MIDPOINTS
% GEOMETRY & LOADING
% ----------------------------- % -----------------------------
1 = 1; L2 = 1; L3 = 1; % Segment lengths [m] stress = zeros(2,1);
dof = [2*elements(e,1)-1 2*elements(e,1) 2*elements(e,2)-1 2*elements(e,2)];
x_mid = zeros(2,1);
= 12e3; % Uniform load on segment 2-3 [N/m]
K(dof, dof) = K(dof, dof) + ke;
for e = 1:2
% ----------------------------- x1 = nodes(elements(e,1));
% Distributed load on second element
% NODES AND ELEMENT CONNECTIVITY x2 = nodes(elements(e,2));
if e == 2
% ----------------------------- Le = x2 - x1;
fe = q * Le / 2 * [1; Le/6; 1; -Le/6];
odes = [0, L1, L1+L2]; % Nodal positions [m]
F(dof) = F(dof) + fe;
lements = [1 2; 2 3]; % Element connectivity
end dof = [2*elements(e,1)-1 2*elements(e,1) 2*elements(e,2)-1 2*elements(
umNodes = length(nodes);
end ue = U(dof);
umDOF = 2 * numNodes; % DOFs per node: [v, theta]
% -----------------------------
% APPLY BOUNDARY CONDITIONS % Bending moment at midpoint of element
% -----------------------------
% ----------------------------- M = E*I * (-6/Le^2 * ue(1) - 4/Le * ue(2) + 6/Le^2 * ue(3) - 2/Le * ue(4));
% INITIALIZE GLOBAL MATRICES
fixedDOFs = [1, 2, 3, 5]; % Fixed: v1, θ1, v2, v3 stress(e) = -M * z / I; % Bending stress at top fiber
% -----------------------------
freeDOFs = setdiff(1:numDOF, fixedDOFs); x_mid(e) = (x1 + x2) / 2;
= zeros(numDOF); % Global stiffness matrix
End
= zeros(numDOF,1); % Global force vector
% -----------------------------
MATLAB
stress report
stress, idx] = max(abs(stress));
'Maximum bending stress = %.2f MPa at x = %.2f m\n', max_stress/1e6, x_mid(idx));
% --- Bending Moment Diagram (Line) ---
nexttile;
----------------------- plot(x_mid, moments / 1e3, '-o', 'LineWidth', 2, 'Color', [0.1 0.6 0.1]);
TTING ENHANCED RESULTS xlabel('Length (m)');
----------------------- ylabel('Moment (kNm)');
actor = 1000; % Scale factor for exaggerated deflection title('Bending Moment at Midpoints');
grid on;
ds = nodes;
ds = U(1:2:end) * scaleFactor; % --- Stress Distribution (Stem Plot) ---
nexttile;
stem(x_mid, stress / 1e6, 'filled', 'LineWidth', 1.8, 'Color', 'm');
'Color','w'); hold on;
yout(3,1); [maxVal, maxIdx] = max(abs(stress));
text(x_mid(maxIdx), stress(maxIdx)/1e6, ...
sprintf(' Max: %.2f MPa', stress(maxIdx)/1e6), ...
eformed Shape (Smooth Line) --- 'Color', 'r', 'FontSize', 10, 'FontWeight', 'bold');
e; xlabel('Length (m)');
nspace(nodes(1), nodes(end), 100); ylabel('Stress (MPa)');
nterp1(x_coords, y_coords, xx, 'spline'); title('Top Fiber Stress Distribution');
, yy, 'b-', 'LineWidth', 2); hold on; grid on;
coords, zeros(size(x_coords)), 'k--', 'LineWidth', 1.2); % Undeformed
(x_coords, y_coords, 40, 'ro', 'filled'); % Nodes
'Length (m)');
'Deflection (mm)');
mooth Deformed Shape (Exaggerated)');
('Deformed', 'Undeformed', 'Nodes');
;
MATLAB
Problem
MATLAB
% Loop over elements and assemble
for e = 1:n_elem
i = conn(e,1); j = conn(e,2); fprintf("Vertical deflection at point C = %.4f mm\n", deflection_C)
% Problem parameters
le = x(j) - x(i); fprintf("Slope at point B = %.6f radians\n", slope_B);
= 200e3; % MPa
ke = E*I/le^3 * [12 6*le -12 6*le;
= 500e6; % mm^4
6*le 4*le^2 -6*le 2*le^2;
= 200; % mm
-12 -6*le 12 -6*le; % (b) Stress distribution at top fiber (z = +h/2)
1 = 9000; % mm
6*le 2*le^2 -6*le 4*le^2]; z = h / 2; % mm
2 = 3000; % mm
fe = zeros(4,1); stress = zeros(n_elem,1);
= L1 + L2; % Total length
% Apply UDL on AB span x_elem = zeros(n_elem,1);
if x(i) < L1
fe = q*le/2 * [1; le/6; 1; -le/6];
% FEM settings
end for e = 1:n_elem
_AB = 10; % Elements in AB
_BC = 5; % Elements in BC i = conn(e,1); j = conn(e,2);
_elem = n_AB + n_BC; le = x(j) - x(i);
dof = [2*i-1 2*i 2*j-1 2*j]; dof = [2*i-1 2*i 2*j-1 2*j];
_nodes = n_elem + 1;
K(dof,dof) = K(dof,dof) + ke; ue = u(dof);
F(dof) = F(dof) + fe;
end
% Node coordinates
= linspace(0, L, n_nodes)'; % Curvature (second derivative of displacement shape function)
M = E*I/le^2 * [-6 -4*le 6 -2*le] * ue;
% Point load at node C (55 kN) stress(e) = -M * z / I;
F(end-1) = F(end-1) + -55e3; % Negative for downward x_elem(e) = (x(i) + x(j)) / 2;
% Element connectivity
onn = [(1:n_elem)', (2:n_elem+1)']; end