import math
import matplotlib.pyplot as plt
%matplotlib inline
#Initilization of variables
w=196 #N/m
M_app=4000 #N.m
L=6 #m
#Calculations
#Taking Moment about Point L and equating it to 0
R_r=(M_app+w*L*L*0.5)/(3*L) #N
#Taking Moment about Point R and equating it to 0
R_l= ((((2*L)+(L/2))*(w*L))-(M_app))/(3*L) #N
#finding point of zero shear
a=R_l*w**-1
#defining x
x0=[0,18]
x=[0,0.5,1,1.5,2,2.5,3,3.5,a,4,4.5,5,5.5,6] #for 0<x<6
x1=[6,12] #for6<x<12
x2=[12,18] #for 12<x<18
xv=[6,12,18] #specially for shear force
xo=[12.001,12.002] #Straight line plot
#Shear Force Calculations
#Summing forces in vertical direction and equating to 0
V1=(R_l-w*x[0],R_l-w*x[1],R_l-w*x[2],R_l-w*x[3],R_l-w*x[4],R_l-w*x[5],R_l-w*x[6],R_l-w*x[7],R_l-w*x[8],R_l-w*x[9],R_l-w*x[10],R_l-w*x[11],R_l-w*x[12],R_l-w*x[13]) #N for 0<x<6
V2=(R_l)-(w*L) #N for 6<x<18
#Bending Moment Calculations
M1=(R_l*x[0]-w*x[0]**2*0.5,R_l*x[1]-w*x[1]**2*0.5,R_l*x[2]-w*x[2]**2*0.5,R_l*x[3]-w*x[3]**2*0.5,R_l*x[4]-w*x[4]**2*0.5,R_l*x[5]-w*x[5]**2*0.5,R_l*x[6]-w*x[6]**2*0.5,R_l*x[7]-w*x[7]**2*0.5,R_l*x[8]-w*x[8]**2*0.5,R_l*x[9]-w*x[9]**2*0.5,R_l*x[10]-w*x[10]**2*0.5,R_l*x[11]-w*x[11]**2*0.5,R_l*x[12]-w*x[12]**2*0.5,R_l*x[13]-w*x[13]**2*0.5) #N.m for 0<x<6
M2=(R_l*x1[0]-((w*L)*(x1[0]-3)),R_l*x1[1]-((w*L)*(x1[1]-3))) #N.m for 6<x<12
M3=(R_l*x2[0]-((w*L)*(x2[0]-3))+M_app,R_l*x2[1]-((w*L)*(x2[1]-3))+M_app) #N.m for 12<x<18
Mo=[-1464.8652,2509.3333]
#Maximum bending moment
M_max=R_l*a*0.5 #N.m
#Plotting SFD & BMD
p=[0,a,5.99,6,11.99,12,17.99,18]
y=[0,1467,1020,1020,-1486,2514,0,0]
z=[0,a,5.99,6,11.99,12,17.99,18]
b=[758,0,-418,-418,-418,-418,-418,0]
g=[0,0,0,0,0,0,0,0]
d=transpose(p)
e=transpose(b)
plt.plot(d,y,d,g)
xlabel('Span (m)')
ylabel('B.M (N.m)')
plt.show()
xlabel('Span (m)')
ylabel('S.F (N)')
plt.plot(z,e,z,g)
plt.show()
#Result
print'The value of reactions are: R_l=',round(R_l),"N",'and R_r=',round(R_r),"N"
print'The point of maximum bending moment is',round(a,2),"meters from left support",'and maximum bending moment is',round(M_max),"N.m"
print'The bending moment and shear force diagrams have been plotted'