##Ex5_1
import math
Vm = 24.
RL = 1.8*10**3
Im = Vm/RL
Irms = Im/2.
Idc = Im/(math.pi)
r = ((Irms/Idc)**2. - 1.)**.5
print'%s %.2f %s'%("Vm = ",(Vm),"V")##applied voltage to half wave rectifier
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
print'%s %.2f %s'%("Im = Vm/RL = ",(Im),"A")##peak current
print'%s %.2f %s'%("Irms = Im/2 = ",(Irms),"A")##rms current
print'%s %.2e %s'%("Idc = Im/pi = ",(Idc),"A")##D.C. current
print'%s %.2f %s'%("r= ",(r),"")##ripple factor
##Ex5_2
import math
Vm = 18.
##in half wave circuit
Vdc = Vm/math.pi
PIV = Vm
print'%s %.2f %s'%("Vm = ",(Vm),"V")##peak voltage to rectifier
print'%s %.2f %s'%("Vdc = Vm/pi = ",(Vdc),"V")##D.C. voltage
print'%s %.2f %s'%("PIV = Vm = ",(PIV),"V")##peak inverse voltage
##in full wave circuit
Vdc = (2.*Vm/math.pi)
PIV = 2.*Vm
print'%s %.2f %s'%("Vdc = 2*Vm/pi = ",(Vdc),"V")##D.C. voltage
print'%s %.2f %s'%("PIV = 2*Vm = ",(PIV),"V")##peak inverse voltage for center trapped
##in full wave Bridge rectifier
print'%s %.2f %s'%("PIV = Vm = ",(Vm),"V")##peak inverse voltage
##Ex5_3
import math
Vm = 12.
RL = 1.5*10**3
Im = Vm/RL
Irms = Im/(2**.5)
Idc = (2.*Im/math.pi)
r =(((Irms/Idc)**2)-1.)**.5
print'%s %.2f %s'%("Vm = ",(Vm),"V")##peak voltage to full rectifier
print'%s %.2f %s'%("Im = Vm/RL = ",(Im),"A")##peak current
print'%s %.2f %s'%("Irms = Im/(2^0.5) = ",(Irms),"A")##rms current
print'%s %.2f %s'%("Idc = (2*Im/pi) = ",(Idc),"A")##D.C. current
print'%s %.2f %s'%("r= ",(r),"")##ripple factor
##Ex5_4
import math
Idc = 10*10**-3
Irms = 14*10**-3
RL = 1*10**3
Pdc = (Idc**2)*RL
Pac = (Irms**2)*RL
print'%s %.2f %s'%("Idc = ",(Idc),"A")##D.C. current
print'%s %.2f %s'%("Irms = ",(Irms),"A")##rms current
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
print'%s %.2f %s'%("Pdc = (Idc^2)*RL = ",(Pdc),"W")##D.C. power
print'%s %.2f %s'%("Pac = (Irms^2)*RL = ",(Pac),"W")##A.C. power
print'%s %.2f %s'%("eta_r = Pdc/Pac = ",(Pdc/Pac*100),"%")##Rectification efficiency
##Ex5_5
import math
print("v = 12 sin(wt)")
Vm = 12.
RL = 1*10**3
Rf = 10.
Im = Vm/(RL+Rf)
Idc =Im/math.pi
Vdc = Idc*RL
Irms = Im/2.
Pi = (Irms**2)*(RL+Rf)
VNL = Vm/math.pi
VL = Idc*RL
Regulation = (VNL - VL)/VL
print'%s %.2f %s'%("Vm = ",(Vm),"V")##amplitude of applied signal
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
print'%s %.2f %s'%("Rf = ",(Rf),"ohm")##forward resistance
print'%s %.2f %s'%("Im = Vm/(RL+Rf) = ",(Im),"A")##peak current
print'%s %.2f %s'%("Idc = Im/pi = ",(Idc),"A")##D.C. current
print'%s %.2f %s'%("Vdc = Idc*RL = ",(Vdc),"V")##D.C, voltage
print("Pi = (Irms^2)*(RL+Rf)")
print'%s %.2f %s'%("Irms = Im/2 = ",(Irms),"A")##rms current
print'%s %.2f %s'%("Pi = ",(Pi),"W")##input power
print("%Regulation = (VNL - VL)/VL")
print'%s %.2f %s'%("VNL = Vm/pi = ",(VNL),"V")##non load voltage
print'%s %.2f %s'%("VL = Idc*RL = ",(VL),"")##load voltage
print'%s %.2f %s'%("%Regulation = ",(Regulation*100),"%")##percentage regulation
## NOTE : THE POWER CALCULATED IN THE TEXTBOOK IS WRONG.
##Ex5_6
import math
Vdc = 15.
print'%s %.2f %s'%("Vdc = ",(Vdc),"V")##applied D.C. voltage
##Half Wave Rectifier
Vm = math.pi*Vdc
PIV = Vm
print'%s %.2f %s'%("Vm = Vdc*pi = ",(Vm),"V")##D.C. voltage for half wave rectifier
print'%s %.2f %s'%("PIV = Vm = ",(PIV),"V")##peak inverse voltage for half wave rectifier
##Full Wave Rectifier
Vm = math.pi*Vdc/2.
PIV = 2.*Vm
print'%s %.2f %s'%("Vm = Vdc*pi/2 = ",(Vm),"V")##D.C. voltage for full wave rectifier
print'%s %.2f %s'%("PIV = 2*Vm = ",(PIV),"V")##peak inverse voltage for full wave rectifier
##Bridge Rectifier
Vm = math.pi*Vdc/2.
PIV = Vm
print'%s %.2f %s'%("Vm = Vdc*pi/2 = ",(Vm),"V")##D.C. voltage for bridge rectifier
print'%s %.2f %s'%("PIV = Vm = ",(PIV),"V")##peak inverse voltage for bridge rectifier
##Ex5_11
import math
Rf = 10.
RL = 150.
eta_r = 40.6/(1.+Rf/RL)
print'%s %.2f %s'%("Rf = ",(Rf),"ohm")##forward resistance
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
print'%s %.2f %s'%("eta_r = 40.6/(1+Rf/RL) = ",(eta_r),"%")##rectification efficiency
##Ex5_12
import math
Rf = 12.5
RL = 100.
eta_r = 80.1/(1.+Rf/RL)
print'%s %.2f %s'%("Rf = ",(Rf),"ohm")##forward resistance
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
print'%s %.2f %s'%("eta_r = 80.1/(1+Rf/RL) = ",(eta_r),"%")##rectification efficiency
##Ex5_13
import math
Vdc = 32.
Vm = math.pi*Vdc/2.
Vrms = Vm/(2**.5)
PIV = Vm
print'%s %.2f %s'%("Vdc = ",(Vdc),"V")##D.C. voltage
print'%s %.2f %s'%("Vm = pi*Vdc/2 = ",(Vm),"V")##peak voltage
print'%s %.2f %s'%("Vrms = Vm/(2^.5) = ",(Vrms),"V")##rms voltage
print'%s %.2f %s'%("PIV = ",(PIV),"V")##peak inverse voltage
## note : value calculated for Vrms in the textbook is wrong.
##Ex5_14
import math
C = 10.*10**-3
f = 50.
Idc = 200.*10**-3
Vr = Idc/(2.*f*C)
print'%s %.2f %s'%("C = ",(C),"F")##circuit capacitance
print'%s %.2f %s'%("f = ",(f),"Hz")##operating frequency
print'%s %.2f %s'%("Idc = ",(Idc),"A")##D.C. current
print'%s %.2f %s'%("Vr = Idc/(2*f*C) = ",(Vr),"V")##ripple voltage
##Ex5_15
import math
C = 600.*10**-6
T = 20.*10**-3
Vr = 1.2
Vdc = 9.
Vac =Vr/(2.*(3**.5))
r = Vac/Vdc
Idc = (Vr*C)/(T/2.)
RL = Vdc/Idc
print'%s %.2e %s'%("C = ",(C),"F")##rectifier capacitance
print'%s %.2f %s'%("T = ",(T),"s")##time
print'%s %.2f %s'%("Vr = ",(Vr),"V")##ripple voltage
print'%s %.2f %s'%("Vdc = ",(Vdc),"V")##D.C. voltage
print'%s %.2f %s'%("Vac = ",(Vac),"V")##A.C. voltage
print'%s %.2f %s'%("r = ",(r),"")##ripple factor
print'%s %.2f %s'%("Idc = ",(Idc),"A")##D.C. current
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
##Ex5_16
import math
L = 1.## assuming inductance
f = 50.##operating frequency
XL = 2.*math.pi*f*L##inductance
RL = 100.##assuming load resistance
r = .01##ripple factor
##let, capacitances C1 = C2 = C
##that implies XC1 = XC2 = XC
print'%s %.2f %s'%("XL = 2*math.pi*f*L = ",(XL),"ohm")
print'%s %.2f %s'%("r = ",(r),"")
XC = ((r*8.*XL*RL)/(2**.5))**.5##capacitive resistance
print'%s %.2f %s'%("XC = ((r*8*XL*RL)/(2^.5))^.5 = ",(XC),"ohm")
print'%s %.2f %s'%("XC = 1/wC = 1/(2*pi*f*C) = ",(XC),"")
C = 1./(2.*math.pi*f*XC)##capacitance
print'%s %.4f %s'%("C = 1/(2*pi*f*XC) = ",(C),"F")
## thus, design parameters are :
print("design parameters:")
print'%s %.4f %s'%("C1 = C2 = ",(C),"F")
print'%s %.2f %s'%("RL = ",(RL),"ohm")
print'%s %.2f %s'%("L = ",(L),"H")
## Note : the calculations done in the textbook for the given problem is wrong.
##Ex5_17
import math
f =50.
print("vi = 16 sin(wt)")
Vdc = 16.
RL = 100.
C1 = 2.*10**-3
C2 = 2.*10**-3
L = 1.0
Idc = Vdc/RL
XC1 = 1./(2.*math.pi*f*C1)
XC2 = 1./(2.*math.pi*f*C2)
XL = 2.*math.pi*f*L
r = ((2**.5)*XC1*XC2)/(8.*XL*RL)
print'%s %.2f %s'%("L = ",(L),"H")##inductance
print'%s %.4f %s'%("C1 = ",(C1),"F")##capacitance 1
print'%s %.4f %s'%("C2 = ",(C2),"F")##capacitance 2
print'%s %.2f %s'%("RL = ",(RL),"ohm")##load resistance
print'%s %.2f %s'%("f = ",(f),"Hz")##operating frequency
print'%s %.2f %s'%("Vdc = ",(Vdc),"V")##d.c. voltage
print'%s %.2f %s'%("Idc = Vdc/RL = ",(Idc),"A")##d.c. current
print'%s %.2f %s'%("XL = 2*%pi*f*L = ",(XL),"ohm")##inductive resistance
print'%s %.2f %s'%("XC1 = 1/(2*%pi*f*C1) = ",(XC1),"ohm")##capacitive resistance due to capacitance 1
print'%s %.2f %s'%("XC2 = 1/(2*%pi*f*C2) = ",(XC2),"ohm")##capacitive resistance due to capacitance 2
print'%s %.2e %s'%("r = ((2^.5)*XC1*XC2)/(8*XL*RL) = ",(r),"")##ripple factor