Here is how I would approach this problem:
BeamLength = 10;
% N m
PointLoads = [200 0
-100 3;
-100 7;
200 10];
% N/m m m
DistLoads = [-100 1 2;
-100 8 9];
increments = 0.0005;
Positions = 0:increments:BeamLength;
Q = zeros(1, length(Positions) + 1); % shear force (initalization)
[nrOfPLoads, ~] = size(PointLoads);
[nrOfDLoads, ~] = size(DistLoads);
Itterate over every position:
for y = 1:length(Positions)
x = Positions(y); % current position
Q(y+1) = Q(y); % set next position to be the same as the one before (default case)
% pointloads
if ~isempty(PointLoads)
for i = 1:nrOfPLoads % go trough all pointloads
if PointLoads(i,2) == x % position of a pointload
Q(y+1) = Q(y) + PointLoads(i,1); % add shear according to numerical value
end
end
end
% distributed loads
if ~isempty(DistLoads)
for i = 1:nrOfDLoads % go trough all pointloads
if x > DistLoads(i,2) && x < DistLoads(i,3) % position is in between
% add shear (with increment size in mind)
Q(y+1) = Q(y) + DistLoads(i,1) * increments;
end
end
end
end
Now you can leverage that the bending Moment M can be discribed as:
M = -cumtrapz(Q); % do numerical integration
And then plot the results:
figure(1); clf; hold on; grid on;
plot(Positions, Q(1:end-1), LineWidth=2); title("Shear-Force")
figure(2); clf; hold on; grid on;
plot(Positions, M(1:end-1), LineWidth=2); title("Bending Moment")
A few important Notes:
It is important that the beam is already solved and the bearing-forces are represented as point-loads. Otherwise the result will be wrong. Also in this "implementation" distributed loads can not overlap and no pointload can be inside a distributed load. But this should not be a problem in most situations.
Because of the numerical integration the increments should be very small to avoid wrong results. The 0.0005 are sufficient here. Saying this it is also important that the exact position of the point-loads are reached. Otherwise they will be skipped, since I have a "=="-operator to check if the pointload is on this positon.
If such a calculation is nessecary, there are also many online recources which allow to solve a beam and plot the shear-forces and bending moments numerically. You just have to google "solve beam online" and you'll get a few results. There are also recources where the beam-setup can be solved symbolicly. Python has a nice library:
and I also wrote my own program to solve a beam-setup symbolically in MATLAB:
Obviously solving numerically is also possiible there.