import lcr
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
L=1 # inductance in H
C=0.1 #capacitance in F
R=4 #resistance in ohm
f=1 #frequency
w=2*np.pi*f
XL=lcr.inductiveReactance(L,f) #inductive reactance
XC=lcr.capacitiveReactance(C,f) # capacitive reactance
I0=1 # peak current
fs=200 #sample frequency
t= np.arange(0,5,1/fs)
I=I0*np.sin(w*t) # current
V0R=I0*R #peak p.d. across R
V0L=I0*XL #peak p.d. across L
V0C=I0*XC #peak p.d. across C
VR=V0R*np.sin(w*t) # p.d. across R
VL=V0L*np.cos(w*t) # p.d. across L
VC=-V0C*np.cos(w*t) # p.d. across C
plt.figure(figsize = [10,6])
plt.plot(t,I,label = "Current")
plt.plot(t,VR, label = "p.d. across R,phi = 0")
plt.plot(t,VL, label = "p.d. across L,phi = 90")
plt.plot(t,VC, label = "p.d. across C,phi = -90")
plt.xlabel('time(s)',fontsize =14)
plt.ylabel('',fontsize =14)
plt.legend()
plt.title('LCR circuit',fontsize =18,color='r')
plt.show()
Z=lcr.impedance(L,C,R,f) #impedance of LCR
phi=lcr.phase(L,C,R,f) # phase
ZLR=lcr.impedance(L,0,R,f) #impedance of LR
phiLR=lcr.phase(L,0,R,f) #phase of LR
ZCR=lcr.impedance(0,C,R,f) #impedance of CR
phiCR=lcr.phase(0,C,R,f) #phase of CR
V0=I0*Z # peak voltage of LCR
V0LR=I0*ZLR #peak voltage of LR
V0CR=I0*ZCR # peak voltage of CR
V=V0*np.sin(w*t+phi) # p.d. acrosss LCR
VLR=V0LR*np.sin(w*t+ phiLR) # p.d. acrosss LR
VCR=V0CR*np.sin(w*t+ phiCR) # p.d. acrosss LR
plt.figure(figsize = [10,6])
plt.plot(t,I, label = "Current")
plt.plot(t,V, label = "p.d. across LCR, phi="+str(phi*180/np.pi))
plt.plot(t,VLR, label = "p.d. across LR,phi ="+str(phiLR*180/np.pi))
plt.plot(t,VCR, label = "p.d. across CR, phi ="+str(phiCR*180/np.pi))
plt.xlabel('time(s)',fontsize =14)
plt.ylabel('Value',fontsize =14)
plt.legend()
plt.title('LCR circuit',fontsize =18,color='r')
plt.show()