# 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
!pip install pandas
import pandas as pd
import numpy as np
!pip install openpyxl
#Code cell provided for calculations of the theoretical resonant wavelenths and frequencies.
#Show your work to receive credit.
W = 2 * 1.22
W2 = 2 * 1.22/2
W3 = 2 * 1.22/3
W4 = 2 * 1.22/4
W5 = 2 * 1.22/5
print(W)
print(W2)
print(W3)
print(W4)
print(W5)
#We note that the wavelengths are independent of mass
v = np.sqrt((100 * 9.8/1000)/0.0012)
F1 = v/W
F2 = v/W2
F3 = v/W3
F4 = v/W4
F5 = v/W5
print(F1)
print(F2)
print(F3)
print(F4)
print(F5)
#Since the mass is doubled, we now create f1, f2, f3... which are F1, F2, F3 * sqrt(2)
f1 = F1 * np.sqrt(2)
f2 = F2 * np.sqrt(2)
f3 = F3 * np.sqrt(2)
f4 = F4 * np.sqrt(2)
f5 = F5 * np.sqrt(2)
print(f1)
print(f2)
print(f3)
print(f4)
print(f5)
#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
def wavelength_computation_and_error(mass, frequency, original_wavelength):
wavelength = np.sqrt(9.8 * mass/0.0012)/frequency
error = (wavelength - original_wavelength)/original_wavelength * 100
print(wavelength)
print(error)
wavelength_computation_and_error(0.1, 11.2, 2.44)
wavelength_computation_and_error(0.1, 22.3, 1.22)
wavelength_computation_and_error(0.1, 35.5, 0.8133333333333334)
wavelength_computation_and_error(0.1, 48.7, 0.61)
wavelength_computation_and_error(0.1, 61.2, 0.488)
wavelength_computation_and_error(0.2, 16.3, 2.44)
wavelength_computation_and_error(0.2, 33, 1.22)
wavelength_computation_and_error(0.2, 52.5, 0.8133333333333334)
wavelength_computation_and_error(0.2, 70, 0.61)
wavelength_computation_and_error(0.2, 87.3, 0.488)
#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)
L = 1.22 #m
w_1 = v_air/132
w_2 = v_air/269
w_3 = v_air/405
w_4 = v_air/529
w_5 = v_air/656
wavelength_1 = 2 * L
wavelength_2 = 2 * L/2
wavelength_3 = 2 * L/3
wavelength_4 = 2 * L/4
wavelength_5 = 2 * L/5
f1 = v_air/wavelength_1
f2 = v_air/wavelength_2
f3 = v_air/wavelength_3
f4 = v_air/wavelength_4
f5 = v_air/wavelength_5
print(f1)
print(f2)
print(f3)
print(f4)
print(f5)
print(w_1)
print(w_2)
print(w_3)
print(w_4)
print(w_5)
print(wavelength_1)
print(wavelength_2)
print(wavelength_3)
print(wavelength_4)
print(wavelength_5)
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(stringmodes):
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()