#run me!
import matplotlib.pyplot as plt
import numpy as np
from scipy import signal
from scipy import optimize
# Cell for calculations
V_R = 4
R = 33.95
I = V_R/R
print(I)
### Edit this line ###
phi = 0
### End edit ###
frequency = 850 #Hz
time = np.linspace(0,5*1/frequency,1000)
angular_freq = 2*np.pi*frequency
audio_driver = 100*np.sin(angular_freq*time)
#the max current is not necessarily 0.1 A or 100 mA, we are just using this for a visualization
resistor_voltage = 4*np.sin((angular_freq*time)+phi)
fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
ax1.plot(time*1000,resistor_voltage,'g')
ax2.plot(time*1000,audio_driver,'r')
plt.title('Resistor Current and Voltage vs. Time')
ax1.set_xlabel('Time [ms]')
ax1.set_ylabel('Voltage across Resistor [V]', color='g')
ax2.set_ylabel('Current [mA]', color='r')
ax1.set_ylim([-6,6])
plt.show()
# Cell for calculations
phi_C = 0.3/1.2 * 360
print(phi_C)
C = 1e-5 # F
### Edit this line ###
phi_C = -np.pi/2
### End edit ###
cap_voltage = 2*np.sin((angular_freq*time)+phi_C)
plt.figure()
plt.plot(time*1000,resistor_voltage,'r', label='Voltage Across the Resistor')
plt.plot(time*1000,cap_voltage,'g', label='Voltage Across the Capacitor')
plt.title('Capacitor and Resistor Voltages vs. Time')
plt.xlabel('Time [ms]')
plt.ylabel('Voltage [V]')
plt.legend(bbox_to_anchor=(1.05, 1))
plt.show()
# Cell for calculations
V_C = 2
Z_C = V_C/I
print(Z_C)
# Cell for calculations
C = 10e-6
w = 850 * 2 * np.pi
Z_C = 1/C/w
print(Z_C)
# Cell for calculations
phi_L = 0.9/1.2 * 360
print(phi_L)
L = 8.2e-3 # H
### Edit this line ###
phi_L = -3*np.pi/2
### End edit ###
#the voltage across the capacitor is not 2 V necessarily, we are just using this for a visualization
ind_voltage = 5.*np.sin((angular_freq*time)+phi_L)
plt.figure()
plt.plot(time*1000,resistor_voltage,'r', label = 'Voltage Across the Resistor')
plt.plot(time*1000,ind_voltage,'g', label = 'Voltage Across the Inductor')
plt.title('Inductor and Resistor Voltages vs. Time')
plt.xlabel('Time [ms]')
plt.ylabel('Voltage [V]')
plt.legend(bbox_to_anchor=(1.05, 1))
plt.show()
# Cell for calculations
V_L = 5
Z_L = V_L/I
print(Z_L)
# Cell for calculations
L = 8.2e-3
Z_L = w*L
print(Z_L)
# Cell for calculations
phi = 1.1/1.2 * 360
print(phi)
# Cell for calculations
R = 33.95
R_L = 6.7
Z_L = 42.44
Z_C = 18.72
Z = np.sqrt((R + R_L)**2 + (Z_L - Z_C)**2)
print(Z)
V = 5.44
I = V/Z
print(I)
V_bulb = np.array([0.2,0.327,0.812,1.616,2.76,3.890,4.219,3.470,2.2,1.18])
freq_audio = np.array([100,135,182,247,333,450,608,822,1110,1500])
plt.figure()
plt.plot(freq_audio,V_bulb,'k-.')
plt.xlabel('Log(Frequency/[Hz])')
plt.ylabel('Light Bulb Voltage [V]')
plt.xscale('log')
plt.title('Bulb Voltage vs. Log Freqency in RLC circuit.')
# Cell for calculations
L = 8.2e-3
C = 10e-6
f_R = 1/(2*np.pi*np.sqrt(L*C))
print(f_R)
# Cell for calculations
f = 287.4
C = 10e-6
L = 1/(2*np.pi*f)**2/C
print(L)