MATLAB Code
MATLAB Code
% Boundary conditions
A(1,1) = 1; b(1) = 0; % w(0) = 0
A(N,N) = 1; b(N) = 0; % w(L) = 0
A(2,2) = 1; b(2) = 0; % M(0) = 0
A(N,N) = 1; b(N) = 0; % M(L) = 0
% Solve the system
w = A\b;
% Plot results
x = linspace(0, L, N);
plot(x, w, 'b', 'LineWidth', 2);
xlabel('Length of Beam (m)');
ylabel('Deflection (m)');
title('Beam Deflection using Finite Difference Method');
grid on;
3. Centroid of Cross-Section
% Define section dimensions
b1 = 0.01; % Base width (m)
h1 = 0.145; % Base height (m)
b2 = 0.115; % Top width (m)
h2 = 0.01; % Top height (m)
% Compute centroid
A1 = b1 * h1;
A2 = b2 * h2;
y1 = h1 / 2;
y2 = h1 + h2 / 2;
% Plot
figure;
subplot(2,1,1);
plot(x, V, 'r', 'LineWidth', 2);
xlabel('Beam Length (m)'); ylabel('Shear Force (N)');
title('Shear Force Diagram');
grid on;
subplot(2,1,2);
plot(x, M, 'b', 'LineWidth', 2);
xlabel('Beam Length (m)'); ylabel('Bending Moment (Nm)');
title('Bending Moment Diagram');
grid on;
6. Stress Calculation at K and H
% Maximum moment
M_max = max(M);
y_K = y_centroid;
y_H = y_centroid - h1;