Independent Research Project
A PYTHON PROJECT ON GENERATION OF SHEAR FORCE AND BENDING MOMENT DIAGRAMS
Aim of the project
The aim of this project is to calculate the shear forces and bending moments acting on a cantilever beam and a simply supported beam subjected to multiple loading conditions, later generating the shear force and bending moment diagrams.
Objectives
1.To calculate the reaction forces acting on the cantilever and simply supported beams.
2.To calculate the shear forces developing on the beam as a result of the existing forces.
3.To calculate the bending moments developing on the beam as a result of the existing forces at different sections of the beam.
4.To generate the shear force and bending moment diagrams.
5.To develop a modular code that takes information such as the magnitude of forces and other related distances as user-defined inputs.
6.To develop a code that is also modular in terms of selection of the type of beam.
DEFINITIONS
Beam
A beam is a structural element that primarily resists loads applied laterally to the beam's axis. Its mode of deflection is primarily by bending. The loads applied to the beam result in reaction forces at the beam's support points. The total effect of all the forces acting on the beam is to produce shear forces and bending moments within the beam, that in turn induce internal stresses, strains, and deflections of the beam
Shear Force
Shear force is defined as a force that acts in a direction parallel to the surface or a planar cross-section of a body.
In the case of a beam, it is defined as the algebraic sum of the vertical forces acting at any section of the beam on the right or left of the section.
Bending Moment
Bending moment on a beam is defined as the algebraic sum of the moment of all the forces acting on the side of the section.
Depending on the direction of bending, it is classified into two types – sagging if the bending is cup-shaped and the concavity is downwards and hogging if the bending is like a hump with an upward convexity.
CLASSIFICATION OF BEAMS
Depending upon the type of supports, beams are classified as follows :
1) Cantilever
2) Simply (or freely) supported beam
3) Overhanging beam
4) Fixed-beam
5) Continuous beam
Cantilever: A cantilever is a beam whose one end is fixed and the other end free.
In other words, a cantilever is a beam anchored at only one end. The beam carries the load to the support where it is forced against by a moment and shear stress. Cantilevers can also be constructed with trusses or slabs.
Simply Supported Beam: A simply supported beam is one whose ends freely rest on walls or columns or knife edges. In all such cases, the reaction is upwards.
It is one of the simplest structural elements in existence.
It is the type of beam that has pinned support at one end and a roller support at the other end. Depending on the load applied, it undergoes shearing and bending.


TYPES OF LOADINGS
A beam may be subjected to either or in a combination of the following types of loads
Concentrated Or Point Load:-It is a type of load that acts at the center of the beam as shown below.
Uniformly Distributed Load:-It is a type of load which is distributed uniformly over the entire length of the beam.
Uniformly Varying Load:-These are the loads varying uniformly from zero to a particular value and spread over a certain length of the beam. Such a load is also called a triangular load.

SHEAR FORCE AND BENDING MOMENT DIAGRAMS
Shear and bending moment diagrams are analytical tools used in conjunction with structural analysis to help perform structural design by determining the value of shear force and bending moment at a given point of a structural element such as a beam. These diagrams can be used to easily determine the type, size, and material of a member in a structure so that a given set of loads can be supported without structural failure. Another application of shear and moment diagrams is that the deflection of a beam can be easily determined using either the moment area method or the conjugate beam method.
SIGN CONVENTION
The normal sign convention while calculating the shear force and bending moments at various sections of a beam is as follows

SOLUTION
Inputs
The following python code has been written in a modular way that takes inputs such as the magnitude of forces acting on the beam, distances of the forces from the origin, and information regarding uniformly distributed forces.
For loops have been used to define the values of forces and their corresponding distances.
Later, these values are appended to arrays for use in further calculations.
For loop contains statements that would appear on the result screen allowing users to input values of their choice.
The float data type is used to include both decimals and integers.

Input Statements for Uniformly Distributed Loads
A uniformly distributed load generally acts over a span. So the inputs for a udl include starting and ending lengths, the magnitude of the force, total span, the distance of an equivalent point load from origin, etc.

From the figure above, x1 and x2 denote the start and end distances of a udl starting from the origin.
D_O denotes the distance of an equivalent point load from origin.
If there is a case with no udl, the user can type no as the answer, thus eliminating the above questions in the result section.
Determination of the type of beam
An if loop is used containing another question inside for the determination of the type of beam.
Depending upon the answer to this question by the user, the next set of calculations are performed.


CANTILEVER BEAM
Calculation of Reaction Forces
A cantilever beam is fixed at one end and free at the other. So, the reaction force exists at the fixed end.
The following set of code is used to determine the reaction force.
Equations of equilibrium are used to determine the reaction forces and moments.

The Sum function is a predefined function that calculates the sum of elements in an array or a list. Since the reaction force is equal to the sum of other forces and udl acting on the beam, this function is used to calculate the required value.
Calculation of Reaction Moment
Reaction moment is also calculated using the equations of equilibrium, which states that the sum of all the moments acting about a point on the beam would be equal to zero.
From this equation, the reaction at the fixed end is calculated.

Since the moment about a point is defined as the product of the magnitude of the force and its corresponding distance from that point, an array called product is created initially which has values obtained as per the definition above.
Later, the reaction moment is obtained by adding all the values in this array using another for loop.
Shear Force and Bending Moment Calculations(udl and point loads)
When a cantilever beam is subjected to a combination of loads including udl and point loads, the following set of calculations are performed to determine the shear forces and bending moments at various sections of the beam.
Several cases have been covered in the code depending upon the positions of point loads and uniformly distributed loads.
Since shear force and bending moments are subject to changes with respect to positions of loads, four primary cases have been considered in calculations.


Calculation of Shear Force and Bending Moment(only point loads)
In this case, a cantilever beam is subjected to multiple point loads. Udl is absent.
Arrays have been created that store the values of shear forces and bending moments, and the number of elements in these arrays depends on the number of point loads acting on the beam.


Calculation of Shear Force and Bending Moment(only udl)
In this case, only udl is acting on the beam at various positions the number of point loads is zero.
Three conditions have been defined and the shear forces and bending moments have been calculated with respect to these three conditions
The code is as follows.


SIMPLY SUPPORTED BEAM
Calculation of reaction forces
In the case of a simply supported beam, there are two free ends.
As a result, there would be four reaction forces, two in the X direction and two in the Y direction.
Since there are no axial forces or forces in the X direction, the reaction forces in that direction are also assumed to be zero.
The reactions in the Y direction are calculated using the equations of equilibrium which state that the sum of forces acting in the Y direction is zero and the sum of moments about a point is also equal to zero.
The code is as follows.

Calculation of Shear Force and Bending Moment(udl and point loads)
Shear forces have been calculated at various sections of the beam depending on the positions of udl and point loads.
Irrespective of the positions of loads, the shear force at the origin remains the same.

Bending moments are also calculated and are dependent on the positions of loads.
Irrespective of the different positions and magnitude of the loads, the bending moment at the origin and endpoint is always zero

Calculation of shear forces and bending moments(only point loads)
The following code calculates the shear forces and bending moments on various sections of the simply supported beam subjected to single or multiple point loads.
Udl is absent in this case


Calculation of shear forces and bending moments(only udl)
This case deals with the calculation of shear force and bending moments when a simply supported beam is subjected to udl while there are no point loads acting.
Various cases have been considered which depend on the position of the udl


PYTHON CODE
# Python program to generate the shear force and bending moment diagrams of cantilever and simply supported beams
# subject to multiple conditions
import math
import matplotlib.pyplot as plt
import numpy as np
# Inputs
# All forces are to be entered in kN
# All distances are to be entered in m
# The magnitude of UDL is to be entered in kN/m
n = input("enter the number of forces: ")
n = int(n)
#Input statements for forces and their corresponding distance from origin
point_loads = []
plds_1 = []
distances = []
d_1 = []
for i in range(1,n+1):
f_i = float(input('enter the magnitude of ' + str(i) + ' force: '))
point_loads.append(f_i)
plds_1.append(f_i)
l_i = float(input('enter the distance of ' + str(i) + ' force from origin: '))
distances.append(l_i)
d_1.append(l_i)
# Input statement for the total length of the beam
L = float(input('enter the total length of the beam: '))
# Input statements for the parameters of a unifromly distributed load
udl = 0
span = 0
D_O = 0
x1 = 0
x2 = 0
answer = input("Is a Uniformly Distributed Load acting on the beam?")
if answer == "yes":
udl = float(input('enter the magnitude of udl:'))
span = float(input('enter the span of UDL:'))
D_O = float(input('enter the distance of udl converted to point load from origin:'))
x1 = float(input('enter the distance of starting point of udl from origin: '))
x2 = float(input('enter the distance of ending point of udl from origin: '))
elif answer == "no":
print("no udl exists")
# Determination of the type of beam
Type_of_beam = input("enter the type of beam: ")
if Type_of_beam == "cantilever beam":
# Reaction force and moment at the fixed end
# Calculation of reaction force
sum = sum(point_loads)
R_F = sum + (udl*span)
# Calculation of reaction moment
product_ctbeam = []
for i in range(0,n):
p = point_loads[i]*distances[i]
product_ctbeam.append(p)
temp_1 = 0
for j in range(0,len(product_ctbeam)):
temp_1 = temp_1 + product_ctbeam[j]
R_M = temp_1 + (udl*span*D_O)
# Shear force calculation
# The shear force remains constant at origin irrespective of the positions of other loads
if (answer == 'yes') and (len(distances) != 0):
sf_origin = sum + (udl*span)
# Calculation of shear force when a point load is followed by a udl
if distances[0] < x1:
sf_pl1 = sum + (udl*span)
sf_x1 = point_loads[n-1] + (udl*span)
sf_x2 = point_loads[n-1]
# Calculation of shear force when a udl is followed by a point load
elif distances[0] > x1:
sf_x1 = (udl*span) + sum
sf_x2 = sum
sf_pl1 = point_loads[n-1]
# Calculation of shear force when a point load is acting at the end-point of the beam
if distances[n-1] == L:
sf_end = point_loads[n-1]
# Calculation of shear force when a point load is acting ahead of the end-point of the beam
elif distances[n-1] < L:
sf_pl2 = point_loads[n-1]
sf_end = 0
# Plotting the shear force diagrams(following the order of calculation as stated above)
if (distances[0] < x1) and (distances[n-1] == L):
plt.plot([0,distances[0],x1,x2,distances[1]],[sf_origin,sf_pl1,sf_x1,sf_x2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (distances[0] > x1) and (distances[n-1] == L):
plt.plot([0,x1,x2,distances[0],distances[1]],[sf_origin,sf_x1,sf_x2,sf_pl1,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (distances[0] < x1) and (distances[n-1] < L):
plt.plot([0,distances[0],x1,x2,distances[1],L],[sf_origin,sf_pl1,sf_x1,sf_x2,sf_pl2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (distances[0] > x1) and (distances[n-1] < L):
plt.plot([0,x1,x2,distances[0],distances[1],L],[sf_origin,sf_x1,sf_x2,sf_pl1,sf_pl2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
# Calculation of shear forces and plotting the shear force diagrams when point loads are acting and udl is zero
if answer == "no":
sf = []
for k in range(0,n):
add = 0
for l in range(k,n):
add = add + point_loads[l]
sf.append(add)
sf.append(point_loads[n-1])
distances.append(0)
for z in range(n,0,-1):
distances[z] = distances[z-1]
distances[0] = distances[0] - distances[0]
plt.plot(distances,sf)
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
# Calculation of shear forces and plotting the shear force diagrams when udl is acting and point loads are zero
if (len(distances) == 0) and (x1 == 0):
sf_origin = (udl*span)
sf_end = 0
plt.plot([x1,x2],[sf_origin,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (len(distances) == 0) and (x1 != 0):
sf_origin = (udl*span)
sf_x1 = (udl*span)
sf_x2 = 0
plt.plot([0,x1,x2],[sf_origin,sf_x1,sf_x2])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (len(distances) == 0) and (x2 < L):
sf_origin = (udl*span)
sf_x1 = (udl*span)
sf_x2 = 0
sf_end = 0
plt.plot([0,x1,x2,L],[sf_origin,sf_x1,sf_x2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
# Bending Moment Calculations
# In the case of a cantilever beam, the bending moment is zero at the free end
if len(distances) != 0:
# Calculation of bending moment when a point load is followed by a udl
if (distances[0] < x1):
bm_origin = -b - (udl*span*D_O)
bm_pl1 = -(point_loads[1]*(distances[1] - distances[0])) - (udl*span*(D_O - distances[0]))
bm_x1 = -(point_loads[1]*(distances[1] - x1)) - (udl*span*(D_O - x1))
bm_x2 = -(point_loads[1]*(distances[1] - x2))
# Calculation of bending moment when a udl is followed by a point load
elif distances[0] > x1:
bm_origin = -b - (udl*span*D_O)
bm_x1 = -(point_loads[0]*(distances[0] - x1)) - (point_loads[1]*(distances[1] - x1)) - (udl*span*(x2-x1))
bm_x2 = -(point_loads[0]*(distances[0] - x2)) - (point_loads[1]*(distances[1] - x2))
bm_pl1 = -(point_loads[1]*(distances[1] - distances[0]))
# Calculation of bending moment when a point load is acting at the end-point of the beam
if distances[n-1] == L:
bm_end = 0
# Calculation of bending moment when a point load is acting ahead of the end-point of the beam
elif distances[n-1] < L:
bm_pl2 = 0
bm_end = 0
# Plotting the bending moment diagrams(following the order of calculation as stated above)
if (distances[0] < x1) and (distances[n-1] == L):
plt.plot([0,distances[0],x1,x2,distances[1]],[bm_origin,bm_pl1,bm_x1,bm_x2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (distances[0] > x1) and (distances[n-1] == L):
plt.plot([0,x1,x2,distances[0],distances[1]],[bm_origin,bm_x1,bm_x2,bm_pl1,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (distances[0] < x1) and (distances[n-1] < L):
plt.plot([0,distances[0],x1,x2,distances[1],L],[bm_origin,bm_pl1,bm_x1,bm_x2,bm_pl2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (distances[0] > x1) and (distances[n-1] < L):
plt.plot([0,x1,x2,distances[0],distances[1],L],[bm_origin,bm_x1,bm_x2,bm_pl1,bm_pl2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
# Calculation of bending moment and plotting the bending moment diagrams when point loads are acting and udl is zero
if answer == 'no':
distances.pop(0)
bm = []
for i in range(0,n):
sum = 0
for j in range(i,n):
sum = sum - (point_loads[j]*d_1[j])
sub = d_1[i]
for k in range(0,n):
d_1[k] = d_1[k] - sub
bm.append(sum)
bm.append(0)
distances.append(0)
for z in range(n,0,-1):
distances[z] = distances[z-1]
distances[0] = distances[0] - distances[0]
plt.plot(distances,bm)
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
# Calculation of bending moment and plotting the bending moment diagrams when udl is acting and point loads are zero
if (len(distances) == 0) and (x1 == 0):
bm_origin = -(udl*span*D_O)
bm_end = 0
plt.plot([x1,x2],[bm_origin,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (len(distances) == 0) and (x1 != 0):
bm_origin = -(udl*span*D_O)
bm_x1 = -(udl*span*(D_O-x1))
bm_end = 0
plt.plot([0,x1,x2],[bm_origin,bm_x1,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (len(distances) == 0) and (x2 < L):
bm_origin = -(udl*span*D_O)
bm_x1 = -(udl*span*(D_O-x1))
bm_x2 = 0
bm_end = 0
plt.plot([0,x1,x2,L],[bm_origin,bm_x1,bm_x2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif Type_of_beam == "simply supported beam":
# Calculation of reaction forces
sof = 0
for k in range(0,len(point_loads)):
sof = sof + point_loads[k]
product_ssbeam = []
for i in range(0,n):
product_ssbeam.append(point_loads[i]*distances[i])
temp_2 = 0
for j in range(0,len(product_ssbeam)):
temp_2 = temp_2 + product_ssbeam[j]
R_end = (temp_2 + (udl*span*D_O))/(L)
R_origin = sof + (udl*span) - R_end
# Calculation of shear forces
# The shear force remains constant at origin irrespective of the positions of other loads
if (answer == 'yes') and (len(distances) != 0):
sf_origin = sof + (udl*span) - R_end
# Calculation of shear force when a point load is followed by a udl
if distances[0] < x1:
sf_pl1 = sof + (udl*span) - R_end
sf_x1 = point_loads[n-1] + (udl*span) - R_end
sf_x2 = point_loads[n-1] - R_end
# Calculation of shear force when a udl is followed by a point load
elif distances[0] > x1:
sf_x1 = sof + (udl*span) - R_end
sf_x2 = sof - R_end
sf_pl1 = sof - R_end
# Calculation of shear force when a point load is acting at the end-point of the beam
if distances[n-1] == L:
sf_end = point_loads[n-1] - R_end
# Calculation of shear force when a point load is acting ahead of the end-point of the beam
elif distances[n-1] < L:
sf_pl2 = point_loads[n-1] - R_end
sf_end = -R_end
# Plotting of shear force diagrams in the order of calculation above
if (distances[0] < x1) and (distances[n-1] == L):
plt.plot([0,distances[0],x1,x2,L],[sf_origin,sf_pl1,sf_x1,sf_x2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (distances[0] > x1) and (distances[n-1] == L):
plt.plot([0,x1,x2,distances[0],L],[sf_origin,sf_x1,sf_x2,sf_pl1,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (distances[0] < x1) and (distances[n-1] < L):
plt.plot([0,distances[0],x1,x2,distances[1],L],[sf_origin,sf_pl1,sf_x1,sf_x2,sf_pl2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (distances[0] > x1) and (distances[n-1] < L):
plt.plot([0,x1,x2,distances[0],distances[1],L],[sf_origin,sf_x1,sf_x2,sf_pl1,sf_pl2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
# Calculation of shear forces and plotting the shear force diagrams when point loads are acting and udl is zero
if answer == "no":
sf = []
temp_add = 0
for i in range(0,len(plds_1)):
temp_add = temp_add + plds_1[i]
sf.append(temp_add)
for j in range(0,len(sf)):
sf[j] = R_origin - sf[j]
sf.insert(0,R_origin)
sf.insert(len(sf)+1,R_end)
d_1.insert(0,0)
d_1.insert(len(sf)+1,L)
plt.plot(d_1,sf)
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
# Calculation of shear forces and plotting the shear force diagrams when udl is acting and point loads are zero
if (len(distances) == 0) and (x1 == 0):
sf_origin = R_origin
sf_center = 0
sf_end = -R_end
plt.plot([x1,L/2,x2],[sf_origin,sf_center,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (len(distances) == 0) and (x1 != 0):
sf_origin = R_origin
sf_x1 = R_origin - (udl*span)
sf_x2 = R_end
plt.plot([0,x1,x2],[sf_origin,sf_x1,sf_x2])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
elif (len(distances) == 0) and (x2 < L):
sf_origin = R_origin
sf_x1 = R_origin - (udl*span)
sf_x2 = R_origin - (udl*span)
sf_end = R_end
plt.plot([0,x1,x2,L],[sf_origin,sf_x1,sf_x2,sf_end])
plt.xlabel("Length")
plt.ylabel("Shear Force")
plt.show()
# Bending Moment Calculations
# In the case of a simply supported beam, bending moment is zero at supports
if len(distances) != 0:
# Calculation of bending moment when a point load is followed by a udl
if distances[0] < x1:
bm_origin = 0
bm_pl1 = (R_end*(L - distances[0])) - (udl*span*(D_O-distances[0])) - (point_loads[1]*(distances[1]-distances[0]))
bm_x1 = (R_end*(L - x1)) - (udl*span*(D_O - x1)) - (point_loads[1]*(distances[1] - x1))
bm_x2 = (R_end*(L - x2)) - (point_loads[1]*(distances[1] - x2))
# Calculation of bending moment when a udl is followed by a point load
elif distances[0] > x1:
bm_origin = 0
bm_x1 = (R_end*(L - x1)) - (point_loads[0]*(distances[0] - x1)) - (point_loads[1]*(distances[1] - x1)) - (udl*span*(D_O - x1))
bm_x2 = (R_end*(L - x2)) - (point_loads[0]*(distances[0] - x2)) - (point_loads[1]*(distances[1] - x2))
bm_pl1 = (R_end*(L - distances[0])) - (point_loads[1]*(distances[1] - distances[0]))
# Calculation of bending moment when a point load is acting at the end-point of the beam
if distances[n-1] == L:
bm_end = 0
# Calculation of bending moment when a point load is acting ahead of the end-point of the beam
elif distances[n-1] < L:
bm_pl2 = (R_end*(L - distances[1]))
bm_end = 0
# Plotting the bending moment diagrams(in the order stated above)
if (distances[0] < x1) and (distances[n-1] == L):
plt.plot([0,distances[0],x1,x2,L],[bm_origin,bm_pl1,bm_x1,bm_x2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (distances[0] > x1) and (distances[n-1] == L):
plt.plot([0,x1,x2,distances[0],L],[bm_origin,bm_x1,bm_x2,bm_pl1,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (distances[0] < x1) and (distances[n-1] < L):
plt.plot([0,distances[0],x1,x2,distances[1],L],[bm_origin,bm_pl1,bm_x1,bm_x2,bm_pl2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (distances[0] > x1) and (distances[n-1] < L):
plt.plot([0,x1,x2,distances[0],distances[1],L],[bm_origin,bm_x1,bm_x2,bm_pl1,bm_pl2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
# Calculation of bending moment and plotting the bending moment diagrams when point loads are acting and udl is zero
if answer == "no":
if n >> 3:
print("maximum number of forces = 3")
elif n == 3:
bm_origin = 0
bm_pl1 = (R_end*(L - distances[0])) - (point_loads[2]*(distances[2] - distances[0])) - (point_loads[1]*(distances[1] - distances[0]))
bm_pl2 = (R_end*(L - distances[1])) - (point_loads[2]*(distances[2] - distances[1]))
bm_pl3 = (R_end*(L - distances[2]))
bm_end = 0
plt.plot([0,distances[0],distances[1],distances[2],L],[bm_origin,bm_pl1,bm_pl2,bm_pl3,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif n == 2:
bm_origin = 0
bm_pl1 = (R_end*(L - distances[0])) - (point_loads[1]*(L - distances[1]))
bm_pl2 = (R_end*(L - distances[1]))
bm_end = 0
plt.plot([0,distances[0],distances[1],L],[bm_origin,bm_pl1,bm_pl2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif n == 1:
bm_origin = 0
bm_pl1 = (R_end*(L - distances[0]))
bm_end = 0
plt.plot([0,distances[0],L],[bm_origin,bm_pl1,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif n == 0:
print("bmd does not exist")
# Calculation of bending moment and plotting the bending moment diagrams when udl is acting and point loads are zero
if (len(distances) == 0) and (x1 == 0):
bm_origin = 0
bm_center = (udl*(pow(span,2)))/8
bm_end = 0
plt.plot([x1,L/2,x2],[bm_origin,bm_center,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (len(distances) == 0) and (x1 != 0):
bm_origin = 0
bm_x1 = (R_end*(L - x1)) - (udl*span*(D_O - x1))
bm_x2 = 0
plt.plot([0,x1,x2],[bm_origin,bm_x1,bm_x2])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
elif (len(distances) == 0) and (x2 < L):
bm_origin = 0
bm_x1 = (R_end*(L - x1)) - (udl*span*(D_O - x1))
bm_x2 = (R_end*(L - x2))
bm_end = 0
plt.plot([0,x1,x2,L],[bm_origin,bm_x1,bm_x2,bm_end])
plt.xlabel("Length")
plt.ylabel("Bending Moment")
plt.show()
RESULTS
After calculating the shear forces and bending moments on the cantilever and simply supported beams subjected to various loading conditions, the graphs are plotted.
The shear force diagram is obtained by plotting the values of shear force obtained on the Y-axis and the length of sections of the beam on the X-axis.
The bending moment diagram is also obtained by plotting the values of the bending moment and the corresponding section length of the beam.
Depending upon the magnitude of forces and respective distances, the values of shear forces or bending moments can be negative at times.
As a result, the graphs may vary from a range of positive to negative values.
In the case of the cantilever and simply supported beams subjected to a combination of the cantilever and simply supported beams, the shape of the graph is affected by the position of loads.
As a result, plotting conditions have been written for every case considered.
The same can be assumed in the case of beams subjected to only uniformly distributed loads.
The following code is an example of code for plotting the shear force diagram of a cantilever beam subjected to udl and point loads.

This case covers the condition wherein a point load acts ahead of a uniformly distributed load and another point load acts on the endpoint of the beam.
SFD and BMD of a cantilever beam subjected to three point loads




SFD and BMD of a cantilever beam subjected to udl




SFD and BMD of a simply supported beam subjected to udl and two point loads



