# Run this Python cell by selecting it and then pressing shift-enter
# Do not change anything in this cell
# These commands load the libraries for Python to use
import pandas as pd
import numpy as np
#Code cell provided for calculations of the theoretical resonant wavelenths and frequencies.
#Show your work to receive credit.
L = 1.22
mu = .0012
m100 = .1
m200 = .2
F100 = mu * m100
F200 = mu * m200
#48 lam = 2*L/n -> n = # of wavelenghts (1-5)
lam101 = (2*L)
lam102 = (2*L)/2
lam103 = (2*L)/3
lam104 = (2*L)/4
lam105 = (2*L)/5
#44 vel = sqrt(F/mu)
v100 = np.sqrt(F100/mu)*100 #without the 100 multiplier my Hz are off by a factor of 100
v200 = np.sqrt(F200/mu)*100
#43 vel = w/k = f*lam => frec = vel/lam
f101 = v100/lam101
f102 = v100/lam102
f103 = v100/lam103
f104 = v100/lam104
f105 = v100/lam105
f201 = v200/lam101
f202 = v200/lam102
f203 = v200/lam103
f204 = v200/lam104
f205 = v200/lam105
print (lam101,lam102,lam103,lam104,lam105)
print (f101,f102,f103,f104,f105)
print (f201,f202,f203,f204,f205)
#Code cell provided for calculations of the corresponding wavelengths. Show your work to receive credit.
#It may be helpful to first calculate the wavespeed using Eq. 44 for both scenarios and then use Eq. 43 to use
#the wave speed to convert the frequencies from Table 2 into a wavelength.
#To calculate % Error, use (Corresponding - Theoretical)/ Theoretical x 100
#43 vel = w/k = f*lam => frec = vel/lam
#44 vel = sqrt(F/mu)
#frec is known, vel is known.
#lam = vel/frec
f1 = 11.2
f2 = 22.3
f3 = 35.5
f4 = 48.7
f5 = 61.2
f21 = 16.3
f22 = 33
f23 = 52.5
f24 = 70
f25 = 87.3
lam1 = v100/f1
lam2 = v100/f2
lam3 = v100/f3
lam4 = v100/f4
lam5 = v100/f5
lam21 = v200/f21
lam22 = v200/f22
lam23 = v200/f23
lam24 = v200/f24
lam25 = v200/f25
print (lam1,lam2,lam3,lam4,lam5)
print (lam21,lam22,lam23,lam24,lam25)
error1 = (lam1-lam101)/(lam101*100)
error2 = (lam2-lam102)/(lam102*100)
error3 = (lam3-lam103)/(lam103*100)
error4 = (lam4-lam104)/(lam104*100)
error5 = (lam5-lam105)/(lam105*100)
error21 = (lam21-lam101)/(lam101*100)
error22 = (lam22-lam102)/(lam102*100)
error23 = (lam23-lam103)/(lam103*100)
error24 = (lam24-lam104)/(lam104*100)
error25 = (lam25-lam105)/(lam105*100)
print(error1,error2,error3,error4,error5)
print(error21,error22,error23,error24,error25)
#Code cell provided for calculations of the corresponding wavelengths
#and the theoretical resonant wavelengths and frequencies. Show your work to receive credit.
#Eq. 43 and 49 from the Lab Manual will be helpful.
#The first corresponding wavelength column is for your measured frequencies
#The second theo. wavelength column is using Eq. 49, then convert this to frequency with Eq. 43
v_air = 340.3 #m/s (speed of sound in air)
#43 vel = w/k = f*lam => frec = vel/lam
# lam = vel/f
#49 lam = (2L)/n => same as Experiment 1
#2.44 1.22 0.8133333333333334 0.61 0.488
f1 = 132
f2 = 269
f3 = 405
f4 = 529
f5 = 656
lam1 = v_air/f1
lam2 = v_air/f2
lam3 = v_air/f3
lam4 = v_air/f4
lam5 = v_air/f5
theof1 = v_air/lam101
theof2 = v_air/lam102
theof3 = v_air/lam103
theof4 = v_air/lam104
theof5 = v_air/lam105
print(lam1,lam2,lam3,lam4,lam5)
print(theof1,theof2,theof3,theof4,theof5)
df1 = pd.read_excel("Lab11_classdata.xlsx")
#Here we take the columns of the xlsx files and separate them so that each of the resonant frequencies
#for each normal mode can be analyzed separately; we also remove any empty rows with .dropna()
mode1 = df1['number1'].dropna()
mode2 = df1['number2'].dropna()
mode3 = df1['number3'].dropna()
mode4 = df1['number4'].dropna()
mode5 = df1['number5'].dropna()
stringmodes = [mode1,mode2,mode3,mode4,mode5]
def get95PercentConfidenceInterval(mean,sigma,N):
sigma_x = sigma/np.sqrt(N)
print('The Error of the mean is '+str(sigma_x)+'.')
lbof95CI = mean - 1.96*sigma_x
print('The Lower Bound of the 95% confidence interval is '+str(lbof95CI)+'.')
ubof95CI = mean + 1.96*sigma_x
print('The Upper Bound of the 95% confidence interval is '+str(ubof95CI)+'.')
widthof95CI = ubof95CI - lbof95CI
print('The Width of the 95% confidence interval is '+str(widthof95CI)+'.')
for index,mode in enumerate(modes):
mean_mode = np.mean(mode)
std_dev_mode = np.std(mode)
print('Statistics for the resonant frequency of normal mode '+str(index+1))
print('Mean: '+str(mean_mode))
print('Std. Dev.: '+str(std_dev_mode))
print('samples: ' + str(len(mode)))
get95PercentConfidenceInterval(mean_mode,std_dev_mode,len(mode))
print()