calculate shear force diagram and bending moment diagram for indetermined beam in matlab

main.m
% Define the span of the beam and the support locations
L = 5; % Span of the beam
a = 2; % Distance of the left support from the left end of the beam
b = 4; % Distance of the right support from the left end of the beam
P = 10; % Applied load at the center of the beam

% Calculate the reactions at the supports
Rb = P*(b/L); % Reaction at the left support
Ra = P - Rb; % Reaction at the right support

% Distance vector along the beam
x = linspace(0, L, 1000);

% Calculate shear force (V) and bending moment (M) along the beam
V = zeros(size(x));
M = zeros(size(x));

for i = 1:length(x)
    if x(i) <= a
        V(i) = Ra;
        M(i) = Ra*x(i);
    elseif x(i) <= b
        V(i) = Ra - P;
        M(i) = Ra*x(i) - P*(x(i) - a);
    else
        V(i) = Ra - P;
        M(i) = Ra*x(i) - P*(x(i) - a);
    end
end

% Plot the shear force diagram
figure;
plot(x, V, 'b', 'LineWidth', 2);
xlabel('Beam Length (m)');
ylabel('Shear Force (kN)');
title('Shear Force Diagram');

% Plot the bending moment diagram
figure;
plot(x, M, 'r', 'LineWidth', 2);
xlabel('Beam Length (m)');
ylabel('Bending Moment (kNm)');
title('Bending Moment Diagram');
1141 chars
44 lines

gistlibby LogSnag