Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
29 views11 pages

Expy 7

The document outlines several Python programs for engineering experiments, including temperature prediction using multiple regression, deflection calculations for cantilever and simply supported beams, and plotting shear force and bending moment diagrams. Each program takes user inputs for various parameters and outputs calculated values and graphical representations. Additionally, it includes a program to process CSV data and plot amplitude versus time.

Uploaded by

lg3226915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views11 pages

Expy 7

The document outlines several Python programs for engineering experiments, including temperature prediction using multiple regression, deflection calculations for cantilever and simply supported beams, and plotting shear force and bending moment diagrams. Each program takes user inputs for various parameters and outputs calculated values and graphical representations. Additionally, it includes a program to process CSV data and plot amplitude versus time.

Uploaded by

lg3226915
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

Program Created

#Experiment no 7(b)Example of Machine Learning to predict the Temperature,but with multiple


#regression we can throw in more variables,like the weight of the car,to make the prediction more
accurate.

import pandas
from sklearn import linear_model
df=pandas.read_csv("temperature.csv")
X=df[['Avg']]
y=df['Day']
regr=linear_model.LinearRegression()
regr.fit(X,y)
#predict the temperature based on day no of year:
d1=int(input('Enter the date to find forecasted temperature value'))
d=d1+53
#v=float(input("Enter the Temerature in Deg Celcius'))
predictedTemp=((regr.predict([[d]])-32)*5)/9

print('\nThe predicted Average value of Temperature in Deg Celcius based on day number in the year
is=\n',predictedTemp,'Deg.Celcius')

Program Output
C:\Users\mechsim-22\Documents\Akshay>Temperature.py
Enter the date to find forecasted temperature value16
C:\Users\mechsim-22\AppData\Local\Programs\Python\Python312\Lib\site-
packages\sklearn\base.py:493: UserWarning: X does not have valid feature names, but
LinearRegression was fitted with feature names
warnings.warn(

The predicted Average value of Temperature in Deg Celcius based on day number in the year is=
[-9.3550411] Deg.Celcius
Program Created
#Experiment No.8(a)-Program to find deflection of Cantilever Beam under self weight condition and
plot the same
import numpy as np
import matplotlib.pyplot as plt

#user input
l=float(input("Enter the length of beam in mm:"))/1000 #Convert mm to Meters
b=float(input("Enter the breadth of beam in mm:"))/1000 #Convert mm to Meters
h=float(input("Enter the height of beam in mm:"))/1000 #Convert mm to Meters
E=float(input("Enter the Young's Modulus of beam Material in MPa:"))*1e6 #Convert MPa to Pascals
density= float(input("Enter the density of beam material in kg/m^3:"))

#Cross sectional area and momnet of inertia


A=b*h
I=(b*h*3/12) #Moment of inertia

#Distributed load per unit lenth(self weight)


w=density*A*9.81 #N/m (Gravity applied)
#Generate discrete points along the beam lenght
x=np.linspace(0,l,100) #100 Points for smooth curve
#Apply the exact formula for deflection at each point
deflection=-1*(w*x**2/(24*E*I))*(6*l**2-4*l*x+x**2)
#Calculate max deflection at free end
delta_max=-1*(5*w*l**4)/(384*E*I)
print(f"Maximum deflection at free end:{delta_max*1000:.4f}mm")

#Plotting the deflection


plt.figure(figsize=(8,6))
plt.plot(x*1000, deflection*1000, label='Beam Deflection', color='blue')
plt.title('Deflection of Cantileaver Beam under Self Weight')
plt.xlabel('Length of Beam (m)')
plt.ylabel('Deflection (m)')
plt.grid(True)
plt.legend()
plt.show()
Program Output
C:\Users\mechsim-22\Documents\Akshay>"Cantilever beam.py"
Enter the length of beam in mm:11111
Enter the breadth of beam in mm:11255
Enter the height of beam in mm:22556
Enter the Young's Modulus of beam Material in MPa:2e6
Enter the density of beam material in kg/m^3:545
Maximum deflection at free end:-0.0021mm
Program Created
#Experiment No.8(b)-Program to find deflection of simply supported Beam
import numpy as np
import matplotlib.pyplot as plt

# User input
l = float(input("Enter the length of beam in mm: ")) / 1000 # Convert mm to Meters
b = float(input("Enter the breadth of beam in mm: ")) / 1000 # Convert mm to Meters
h = float(input("Enter the height of beam in mm: ")) / 1000 # Convert mm to Meters
E = float(input("Enter the Young's Modulus of beam Material in MPa: ")) * 1e6 # Convert MPa to
Pascals
density = float(input("Enter the density of beam material in kg/m^3: "))

# Cross-sectional area and moment of inertia


A=b*h
I = (b * h**3) / 12 # Moment of inertia for a rectangular section

# Distributed load per unit length (self weight)


w = density * A * 9.81 # N/m (Gravity applied)

# Generate discrete points along the beam length


x = np.linspace(0, l, 100) # 100 Points for smooth curve

# Apply the exact formula for deflection at each point


deflection = (w * x * (l**3 - 2 * l * x**2 + x**3)) / (24 * E * I)

# Calculate max deflection at the center


delta_max = (5 * w * l**4) / (384 * E * I)

print(f"Maximum deflection at the center of the beam: {delta_max * 1000:.4f} mm")

# Plotting the deflection


plt.figure(figsize=(8, 6))
plt.plot(x * 1000, deflection * 1000, label='Beam Deflection', color='blue')
plt.title('Deflection of Simply Supported Beam under Self Weight')
plt.xlabel('Length of Beam (mm)')
plt.ylabel('Deflection (mm)')
plt.grid(True)
plt.legend()
plt.show()
Program Output
C:\Users\mechsim-22>cd C:\Users\mechsim-22\Documents\Akshay
C:\Users\mechsim-22\Documents\Akshay>"simply supported.py"
Enter the length of beam in mm: 4444
Enter the breadth of beam in mm: 1211
Enter the height of beam in mm: 2154
Enter the Young's Modulus of beam Material in MPa: 2e6
Enter the density of beam material in kg/m^3: 555
Maximum deflection at the center of the beam: 0.0000 mm
Program Created
#Experiment 8(c)-Program to plot SFD and BMD of Simply Supported Beam under the point load
import numpy as np
import matplotlib.pyplot as plt

P = float(input('load = '))
u1 = input('load unit = ')
L = float(input('Length of the beam = '))
u2 = input('length unit = ')
a = float(input('Distance of Point load from left end = '))

b=L-a
R1 = P*b/L #reaction force at the left support
R2 = P - R1 #reaction force at the right support
R1 = round(R1, 3)
R2 = round(R2, 3)
print(f'''
As per the static equilibrium, net moment sum at either end is zero,
hence Reaction R1 = P*b/L = {R1} {u1},
Also Net sum of vertical forces is zero,
hence R1+R2 = P, R2 = P - R1 = {R2} {u1}.
''')

l = np.linspace(0, L, 1000)
X = []
SF = []
M = []
maxBM= float()
for x in l:
if x <= a:
m = R1*x
sf = R1
elif x > a:
m = R1*x - P*(x-a)
sf = -R2
M.append(m)
X.append(x)
SF.append(sf)

print(f'''
Shear Force at x (x<{a}), Vx = R1 ={R1} {u1}
at x (x>{a}), SF = R1 - P = {R1} - {P} = -{R1-P} {u1}

Bending Moment at x (x<{a}), Mx = R1*x = {R1}*x


at x (x>={a}), Mx = R1*x - P*(x-{a})
= {R1}x - {P}(x-{a}) = -{R2}x + {P*a}
''')
max_SF = 0
for k in SF:
if max_SF < k:
max_SF = k

print(f'Maximum Shear Force Vmax = {max_SF} {u1}')

for k in M:
if maxBM < k:
maxBM = k
print(f'maximum BM, Mmax = {round(maxBM, 3)} {u1}{u2}')
Mx = float()

for x in l:
if x<a:
Mx = R1*x
if maxBM == Mx:
print(f'maximum BM at x = {round(x,3)} {u2}')
elif x>=a:
Mx = R1*x - P*(x- a)
if maxBM == Mx:
print(f'maximum BM at x = {round(x,3)} {u2}')

#Shear Force Diagram Plot


plt.plot(X, SF)
plt.plot([0, L], [0, 0])
plt.plot([0, 0], [0, R1], [L, L], [0, -R2])
plt.title("SFD")
plt.xlabel("Length in m")
plt.ylabel("Shear Force")
plt.show()

#Bending Moment Diagram Plot


plt.plot(X, M)
plt.plot([0, L], [0, 0])
plt.title("BMD")
plt.xlabel("Length in m")
plt.ylabel("Bending Moment")
plt.show()
Program Output
C:\Users\mechsim-22>cd C:\Users\mechsim-22\Documents\Akshay

C:\Users\mechsim-22\Documents\Akshay>sfdbmd.py
load = 1500
load unit = N
Length of the beam = 500
length unit = M
Distance of Point load from left end = 50

As per the static equilibrium, net moment sum at either end is zero,
hence Reaction R1 = P*b/L = 1350.0 N,
Also Net sum of vertical forces is zero,
hence R1+R2 = P, R2 = P - R1 = 150.0 N.

Shear Force at x (x<50.0), Vx = R1 =1350.0 N


at x (x>50.0), SF = R1 - P = 1350.0 - 1500.0 = --150.0 N

Bending Moment at x (x<50.0), Mx = R1*x = 1350.0*x


at x (x>=50.0), Mx = R1*x - P*(x-50.0)
= 1350.0x - 1500.0(x-50.0) = -150.0x + 75000.0

Maximum Shear Force Vmax = 1350.0 N


maximum BM, Mmax = 67492.492 NM
maximum BM at x = 50.05 M
Program Created
#Experiment No 9 Python Program to process above csv data file and print Amplitude v/s Time plot on
the output screen
import pandas
import numpy as np
import matplotlib.pyplot as plt
import statistics as st
#read the csv data file and assign df as the object to access the same
df = pandas.read_csv("expt9-data.csv")
#as per the column heads assign them to two different lists
t = df['Time']
y = df['v0']
#using stats module find the mean of amplitude
m0 = st.mean(y)
#print the value of time and amplitude
print(t)
print(y)
#plot the amplitude v/s time plot
plt.plot(t,y,color='brown')
plt.axhline(y=m0,color='black',ls='-.')
plt.xlabel('Time in Seconds')
plt.ylabel('Amplitude')
plt.title('Amplitude v/s Time Plot')
plt.show()

Program Output

C:\Users\Akshay Chaudhari>D:
D:\College\pratical\python>"Expt.9-case Study.py"
0 0.000 0 1.313167
1 0.002 1 1.308109
2 0.004 2 1.313167
3 0.006 3 1.308109
4 0.008 4 1.303051
... ...
94 0.188 94 1.389037
95 0.190 95 1.368805
96 0.192 96 1.383979
97 0.194 97 1.394095
98 0.196 98 1.389037
Name: Time, Length: 99, dtype: float64 Name: v0, Length: 99, dtype: float64

You might also like