import numpy as np
#Variable declaration
Diode = np.array([3, 1]); # Declare a diode cell
Diode_1 = [1, 15, 30, 0.5, 0.007]; # Data for Ist diode
Diode_2 = [2, 15, 15, 1.3, 0.20]; # Data for 2nd diode
Diode_3 = [1, 15, 2.5, 5.0, 0.67]; # Data for 3rd diode
Resistor = np.array([5, 1]) # Declare a resistor cell
Resistor_1 = [0.25, 0.026]; # Data for Ist resistor
Resistor_2 = [0.5, 0.038]; # Data for 2nd resistor
Resistor_3 = [1.0, 0.055]; # Data for 3rd resistor
Resistor_4 = [2.5, 0.260]; # Data for 4th resistor
Resistor_5 = [7.5, 0.280]; # Data for 5th resistor
V = 24; # Input voltage, volt
#Calculations&Results
V_Z = Diode_1[1]; # Zener voltage for Ist diode, volt
V_S = V - V_Z; # Voltage drop across series resistor for all the three diodes, volt
#Part (a)
# Diode 1
P_Z = Diode_1[3]; # Power rating of Ist diode, W
I_Z = P_Z/V_Z*1e+03; # Zener current, mA
R_S = V_S/I_Z*1e+03; # Value of series resistance, ohm
P_S = V_S**2/R_S; # Power dissipation across series resistor, watt
print "Diode 1:";
print "========";
print "The value of series resistance = %3d ohm"%R_S;
print "The value of power rating of series resistance = %3.1f W"%P_S
R_S = 270; # Chosen value of series resistor, ohm
P_S = 0.3; # Chosen value of power rating, ohm
print "The suitable value of R_S should be %3d ohm, %3.1f W"%(R_S, P_S);
print "Total unit cost = %5.3f pounds\n"%(Diode_1[4]+Resistor_2[1]);
# Diode 2
print "Diode 2:";
print "========";
P_Z = Diode_2[3]; # Power rating of 2nd diode, W
I_Z = P_Z/V_Z*1e+03; # Zener current, mA
R_S = V_S/I_Z*1e+03; # Value of series resistance, ohm
P_S = V_S**2/R_S; # Power dissipation across series resistor, watt
print "The value of series resistance = %5.2f ohm"%R_S
print "The value of power rating of series resistance = %4.2f W"%P_S
R_S = 120; # Chosen value of series resistor, ohm
P_S = 1.0; # Chosen value of power rating, ohm
print "The suitable value of R_S should be %3d ohm, %3.1f W"%(R_S, P_S);
print "Total unit cost = %4.2f pounds"%(Diode_2[4]+Resistor_3[1]);
# Diode 3
print "\nDiode 3:";
print "========";
P_Z = Diode_3[3]; # Power rating of 3rd diode, W
I_Z = P_Z/V_Z*1e+03; # Zener current, mA
R_S = V_S/I_Z*1e+03; # Value of series resistance, ohm
P_S = V_S**2/R_S; # Power dissipation across series resistor, watt
print "The value of series resistance = %3d ohm"%R_S;
print "The value of power rating of series resistance = %3.1f W"%P_S
R_S = 27; # Chosen value of series resistor, ohm
P_S = 7.5; # Chosen value of power rating, ohm
print "The suitable value of R_S should be %3d ohm, %3.1f W"%(R_S, P_S);
print "Total unit cost = %4.2f pounds"%(Diode_3[4]+Resistor_5[1]);
# Part (b)
delta_V_Z = (5*15)/100; # Allowable change in V_Z, volt
delta_I_Z = 30e-03; # Allowable change in zener current, A
delta_VZ = np.zeros(3);
delta_VZ_1 = 30e-03*30; # Change in zener voltage dor diode 1, V
delta_VZ_2 = 30e-03*15; # Change in zener voltage dor diode 2, V
delta_VZ_3 = 30e-03*2.5; # Change in zener voltage dor diode 3, V
print "\nThe maximum value of zener voltage change = %4.2f V"%(max(delta_VZ_2, delta_VZ_3));
print "To meet the specification at lowest cost, circuit 2 would be adopted";