<jupyter_start><jupyter_text>Lab 6: Calculations  Part 1: Differential Pressure Measurments<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os
import math
dirPath = os.path.realpath('.')
fileName = 'rawData/lab 6 measurements (2).xlsx'
filePath = os.path.join(dirPath, fileName)
df = pd.read_excel(filePath,sheetname="Part1",header=0)
print(df)
cols = df.columns<jupyter_output>deltah(cm)  error(cm)  V (mV)  error (mV)  deltah(cm).1  error(cm).1  \
0            0          1       1           1           -75            1   
1           -5          1     -17           1           -70            1   
2          -10          1     -34           1           -65            1   
3          -15          1     -54           1           -60            1   
4          -20          1     -67           1           -55            1   
5          -25          1     -86           1           -50            1   
6          -30          1    -106           1           -45            1   
7          -35          1    -122           1           -40            1   
8          -40          1    -141           1           -35            1   
9          -45          1    -160           1           -30            1   
10         -50          1    -177           1           -25            1   
11         -55          1    -194           1           -20            1   
12         -[...]<jupyter_text>Plotting<jupyter_code>plt.figure(1)
plt.errorbar(df[cols[0]],df[cols[2]],xerr=2*df[cols[1]],yerr=2*df[cols[3]])
plt.errorbar(df[cols[4]],df[cols[6]],xerr=2*df[cols[5]],yerr=2*df[cols[7]])
plt.title('Voltage vs delta h')
plt.xlabel('delta h (cm)')
plt.ylabel('Voltage (mV)')
plt.legend(['Ramp Down','Ramp Up'])
plt.grid()
plt.savefig('pressure.png')
plt.show()<jupyter_output><empty_output><jupyter_text>Plot again, but zoom in so that error bars are visible<jupyter_code>plt.figure(1)
plt.errorbar(df[cols[0]],df[cols[2]],xerr=2*df[cols[1]],yerr=2*df[cols[3]])
plt.errorbar(df[cols[4]],df[cols[6]],xerr=2*df[cols[5]],yerr=2*df[cols[7]])
plt.title('Voltage vs delta h (Hysteresis Effects)')
plt.xlabel('delta h (cm)')
plt.ylabel('Voltage (mV)')
plt.legend(['Ramp Down','Ramp Up'])
plt.axis([-10,1,-50,5])
plt.grid()
plt.savefig('pressureHysteresis.png')
plt.show()<jupyter_output><empty_output><jupyter_text>Sensitivity Calculations<jupyter_code>sensitivity = df['V (mV)'][1:]/df['deltah(cm)'][1:]
print('sensitivity =',np.average(sensitivity), 'mV/cm')

sens_error = np.sqrt((df['error(cm)'][1:]/df['V (mV)'][1:])**2 + (df['error (mV)'][1:]/df['deltah(cm)'][1:])**2)*sensitivity
print('sensitivity error =', np.average(sens_error), 'mV/cm')<jupyter_output>sensitivity = 3.51078806379 mV/cm
sensitivity error = 0.159453662338 mV/cm<jupyter_text>Sensitivity with Hysteresis Effects Calculations<jupyter_code>sensitivity_h = df['V (mV).1'][0:10]/df['deltah(cm).1'][0:10]
print(sensitivity_h)
print('sensitivity =',np.average(sensitivity_h), 'mV/cm')

sens_error_h = np.sqrt((df['error(cm).1'][0:10]/df['V (mV).1'][0:10])**2 + (df['error (mV)'][0:10]/df['deltah(cm).1'][0:10])**2)*sensitivity_h
print('sensitivity error =', np.average(sens_error_h), 'mV/cm')<jupyter_output>0    3.600000
1    3.642857
2    3.676923
3    3.700000
4    3.745455
5    3.780000
6    3.800000
7    3.875000
8    3.885714
9    3.966667
dtype: float64
sensitivity = 3.76726157176 mV/cm
sensitivity error = 0.0813336209479 mV/cm<jupyter_text>Effects of Hysteresis<jupyter_code>hysteresisOffset = df[cols[1]][0]-df[cols[6]][len(df[cols[4]])-1]
print('Hysteresis Offset =', hysteresisOffset,'mV')
hysteresisError = np.sqrt(1**2 + 1**2)
print('Hysteresis Error =',hysteresisError, 'mV')<jupyter_output>Hysteresis Offset = 16 mV
Hysteresis Error = 1.41421356237 mV<jupyter_text>Part 2: Accelerometer Angle MeasurementsMake a new data frame dfangle to hold the data from the accelAngle sheet.<jupyter_code>dfangle = pd.read_excel(filePath,sheetname="accelAngle",header=0)
print(dfangle)
colsangle = dfangle.columns
plt.figure(2)
plt.errorbar(dfangle[colsangle[2]],dfangle[colsangle[0]],xerr=2*dfangle[colsangle[3]],yerr=2*dfangle[colsangle[1]])
plt.grid()
plt.title('Voltage vs Angle')
plt.ylabel('Angle (degrees)')
plt.xlabel('Voltage (mV)')
plt.savefig('VoltAngle.png')
plt.show()
accArray = []
accArrayError = []
for i in range(0,len(dfangle[colsangle[0]])):
    accArray.append(math.cos(math.radians(np.array(dfangle[colsangle[0]][i]))))
for i in range(0,len(dfangle[colsangle[0]])):    
    accArrayError.append(math.sin(math.radians(np.array(dfangle[colsangle[0]][i]))))
acc = 9.8*np.array(accArray)                      
accError=9.8*math.radians(1)*np.array(accArrayError)
plt.figure(3)
plt.errorbar(dfangle[colsangle[2]],acc,xerr=2*dfangle[colsangle[3]],yerr= accError)
plt.grid()
plt.title('Voltage vs Acceleration')
plt.ylabel('Acceleration (m/s$^2$)')
plt.xlabel('Voltage (mV)')
plt.savefig('VoltAcceleration.png')
plt.show()<jupyter_output><empty_output><jupyter_text>Part 2: Static Measurements<jupyter_code>dfstatic = pd.read_excel(filePath,sheetname="staticMeasurements",header=0)
print(dfstatic)
colsstatic = dfstatic.columns
gravity = 9.81  # m/s/s
kstatic = dfstatic['Force']/dfstatic['disp (m)']
print('kstatic')
print(kstatic)

kstatic_error = kstatic*np.sqrt((dfstatic['Force Error']/dfstatic['Force'])**2 + (dfstatic['error (cm)']/dfstatic['Displacement (cm)'])**2)
print('\n error in kstatic =')
print(kstatic_error)<jupyter_output>kstatic
0    2581.992000
1    1226.795000
2     995.269091
3     906.293077
4     801.362338
dtype: float64

 error in kstatic =
0    365.148810
1     48.193059
2     21.326107
3     12.323961
4      7.359075
dtype: float64<jupyter_text>Part 2: Dynamic Measurements<jupyter_code>dfdynamic = pd.read_excel(filePath,sheetname="dynamicMeasurements",header=0)
print(dfdynamic)
colsdynamic = dfdynamic.columns<jupyter_output>freq (Hz)  error  period  error.1      omega
0       2.17   0.05     440       20  13.634512
1       2.08   0.05     470       20  13.069025
2       2.17   0.05     480       20  13.634512
3       2.22   0.05     440       20  13.948671
4       2.17   0.05     460       20  13.634512<jupyter_text>__NOTE:__ We also need to define the mass<jupyter_code>MASS = 0.2772<jupyter_output><empty_output><jupyter_text>Now lets calculate $k_{dynamic}$<jupyter_code>kdynamic = MASS*dfdynamic['omega']**2
print('kdynamic =')
print(kdynamic)
# now calculate error
num = range(0,5)
kdynamic_error = dfdynamic['error']/dfdynamic['freq (Hz)']*kdynamic*2
print('\nkdynamic error =')
print(kdynamic_error)
plt.figure(4)
plt.errorbar(num,kdynamic,yerr=kdynamic_error,fmt='o')
plt.title('Kdynamic, multiple calculations')
plt.xlabel('Trial Number')
plt.ylabel('k dynamic (N/m)')
plt.legend(['k dynamic'])
plt.axis([-0.1,4.1,0,55])
plt.grid()
plt.savefig('kdynamic.png')
plt.show()
dfWheat = pd.read_excel(filePath,sheetname="Wheatstone",header=0)
print(dfWheat)
colsWheat = dfWheat.columns
R3 = np.linspace(110,130,11)
R1 = 120
R2 = 120
R4 = 120
expectedVout = 30*(R2/(R2+R1)-R4/(R3+R4))
print(expectedVout)
wheatArray = []
for i in range(0,len(dfWheat[colsWheat[0]])):
    wheatArray.append(1/(np.array(dfWheat[colsWheat[0]][i])+120))
    

plt.figure(5)
plt.plot()
plt.errorbar(wheatArray,dfWheat[colsWheat[1]],xerr=0,yerr=2*dfWheat[colsWheat[2]])
plt.grid()
plt.title('Resistance vs Bridge Output Voltage')
plt.ylabel('Voltage (V)')
plt.xlabel('1/(R$_x$ + 120) (mho)')
plt.savefig('Wheatstone.png')
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup