from math import *
import matplotlib.pyplot as plt
def rl_series_waveform(Vm,R,L,f,t):
Z=sqrt(R**2+(2*pi*f*L)**2)
Phi=atan((2*pi*f*L)/R)
Im=Vm/Z
voltage_waveform=[Vm*sin(2*pi*f*x) for x in t]
current_waveform=[Im*sin((2*pi*f*x)-Phi) for x in t]
power_waveform=[voltage*current for voltage,current in zip(voltage_waveform,current_waveform)]
return voltage_waveform,current_waveform,power_waveform
Vm=230*sqrt(2)
R=eval(input("enter the resistance(Ω)"))
L=eval(input("enter the inductance(H)"))
f=50
t=[i*0.0001 for i in range(int(0.02/0.0001))]
voltage,current,power=rl_series_waveform(Vm,R,L,f,t)
#subplot(no. of rows,figures in row,location)
plt.subplot(2,2,1)
plt.plot(t,voltage,label="voltage",color="b")
plt.xlabel("Time(s)")
plt.ylabel("Voltage(V)")
plt.legend()
plt.grid()
plt.subplot(2,2,2)
plt.plot(t,current,label="voltage",color="b")
plt.xlabel("Time(s)")
plt.ylabel("Current(A)")
plt.legend()
plt.grid()
plt.subplot(2,2,2)
plt.plot(t,current,label="current",color="b")
plt.xlabel("Time(s)")
plt.ylabel("Current(A)")
plt.legend()
plt.grid()
plt.subplot(2,2,3)
plt.plot(t,power,label="power",color="b")
plt.xlabel("Time(s)")
plt.ylabel("Power(W)")
plt.legend()
plt.grid()
plt.subplots_adjust(left=0.1,bottom=0.1,right=0.9,top=0.9,wspace=0.4,hspace=0.4)
plt.show()