# 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.
L = 1.2
mu = 0.0012
g = 9.8
F1 = 0.1 * g
F2 = 0.2 * g
waveL_1 = 2*L/1
waveL_2 = 2*L/2
waveL_3 = 2*L/3
waveL_4 = 2*L/4
waveL_5 = 2*L/5
print("Wavelengths")
print(waveL_1)
print(waveL_2)
print(waveL_3)
print(waveL_4)
print(waveL_5)
v1 = np.sqrt(F1/mu)
f1_1 = v1/waveL_1
f1_2 = v1/waveL_2
f1_3 = v1/waveL_3
f1_4 = v1/waveL_4
f1_5 = v1/waveL_5
print("\nFrequency 100g")
print(f1_1)
print(f1_2)
print(f1_3)
print(f1_4)
print(f1_5)
v2 = np.sqrt(F2/mu)
f2_1 = v2/waveL_1
f2_2 = v2/waveL_2
f2_3 = v2/waveL_3
f2_4 = v2/waveL_4
f2_5 = v2/waveL_5
print("\nFrequency 200g")
print(f2_1)
print(f2_2)
print(f2_3)
print(f2_4)
print(f2_5)
#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 percentError(corr_wavelength, theo_wavelength):
return ((corr_wavelength - theo_wavelength) / theo_wavelength * 100)
wL1_100 = v1 / 11.2
wL2_100 = v1 / 22.3
wL3_100 = v1 / 35.5
wL4_100 = v1 / 48.7
wL5_100 = v1 / 61.2
print("Wavelength Corresponding 100g")
print(wL1_100)
print(wL2_100)
print(wL3_100)
print(wL4_100)
print(wL5_100)
print("\nPercent Error 100g")
print(percentError(wL1_100, waveL_1))
print(percentError(wL2_100, waveL_2))
print(percentError(wL3_100, waveL_3))
print(percentError(wL4_100, waveL_4))
print(percentError(wL5_100, waveL_5))
wL1_200 = v2 / 16.3
wL2_200 = v2 / 33.0
wL3_200 = v2 / 52.5
wL4_200 = v2 / 70.0
wL5_200 = v2 / 87.3
print("\nWavelength Corresponding 200g")
print(wL1_200)
print(wL2_200)
print(wL3_200)
print(wL4_200)
print(wL5_200)
print("\nPercent Error 200g")
print(percentError(wL1_200, waveL_1))
print(percentError(wL2_200, waveL_2))
print(percentError(wL3_200, waveL_3))
print(percentError(wL4_200, waveL_4))
print(percentError(wL5_200, waveL_5))
#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)
sWaveL1_corr = v_air/132
sWaveL2_corr = v_air/269
sWaveL3_corr = v_air/405
sWaveL4_corr = v_air/529
sWaveL5_corr = v_air/656
print("Corresonding Wavelengths")
print(sWaveL1_corr)
print(sWaveL2_corr)
print(sWaveL3_corr)
print(sWaveL4_corr)
print(sWaveL5_corr)
sWaveL1_theo = 2*L/1
sWaveL2_theo = 2*L/2
sWaveL3_theo = 2*L/3
sWaveL4_theo = 2*L/4
sWaveL5_theo = 2*L/5
print("\nTheoretical Wavelengths")
print(sWaveL1_theo)
print(sWaveL2_theo)
print(sWaveL3_theo)
print(sWaveL4_theo)
print(sWaveL5_theo)
sTheoF1 = v_air/sWaveL1_theo
sTheoF2 = v_air/sWaveL2_theo
sTheoF3 = v_air/sWaveL3_theo
sTheoF4 = v_air/sWaveL4_theo
sTheoF5 = v_air/sWaveL5_theo
print("\nTheoretical Frequencies")
print(sTheoF1)
print(sTheoF2)
print(sTheoF3)
print(sTheoF4)
print(sTheoF5)
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()