import math
#Variable declaration
#I=Is*(exp((e*V)/kB*T)-1)
I=50*10**(-3)#I=Forward current in ampere
Is=5*10**(-6)#Is=Reverse saturation current in ampere
e=1.6*10**(-19)#e=charge of electron in coulomb
#V=voltage
kB=1.38*10**(-23)#kB=Boltzmann's constant in Joule/kelvin
T=300#T=Temperature in kelvin
#Calculations
a=(I/Is)+1
#exp((e*V)/kB*T)=a
V=((kB*T)/e)*math.log(10**4)
#Result
print "V= %.3f V"%V
import math
#Variable declaration
e=1.6*10**-19#e=charge of an electron in C
V1=0.06#V1=applied forward bias in V
V2=(-0.06)#V2 =applied reverse bias in V
kB=1.38*10**(-23)#kB=Boltzmann's constant in J/K
T=300#T=Temperature in Kelvin
#Calculations
#Is=reverse saturation current in A
#I1=Is*(exp((e*V1)/(kB*T))-1)#I1=current for forward bias
#I2=Is*(exp((e*V2)/(kB*T))-1)#I2=current for reverse bias
a=((math.exp((e*V1)/(kB*T))-1))/((math.exp((e*V2)/(kB*T))-1))#a=(I1/I2)
#Result
print "a = %.2f"%abs(a)
#Variable declaration
V=0.9#V=forward bias voltage
I=60*10**(-3)#I=Current in ampere
#Calculations
rdc=(V/I)#rdc=static resistance in ohm
n=2#n=emission coefficient
rac=((26*n*10**(-3))/I)#rac=dynamic resistance
#Results
print "rdc=%.f ohm"%rdc
print "rac=%.2f ohm"%rac
import math
#Variable declaration
e=1.6*10**(-19)#e=charge of an electron in C
kB=1.38*10**(-23)#kB=Boltzmann's constant in J/K
#V,V1=forward bias voltagesin V
n=2#n=emission coefficient for silicon pn junction diode
T=300#T=Temperature in kelvin
#Calculations
#Is=Reverse saturation current in A
#I=Is*(exp((e*V)/(n*kB*T)))#I=current for forward bias voltage V
#2I=Is*(exp((e*V1)/(n*kB*T)))#2I=current for forward bias voltage V1
#exp((e*(V1-V)/(n*kB*T)))=2
a=(((n*kB*T)/e)*math.log(2))*10**3#a=(V1-V)=increase in the bias voltage in V
#Result
print "V1-V = %.1f mV"%a
import math
#Variable declaration
e=1.6*10**(-19)#e=charge of an electron in C
kB=1.38*10**(-23)#kB=Boltzmann's constant in J/K
n=2#n=emission coefficient for silicon pn junction diode
T=300#T=Temperature in kelvin
#Calculations
#Is=Reverse saturation current in A
#V=bias voltage in V
#I=Is*(exp((e*V)/(n*kB*T))-1)#I=reverse current in A
#I=(-(Is/2))
a=(((n*kB*T)/e)*math.log(1./2))*10**3#a=bias for reverse current in silicon pn junction diode
#Results
print "V = %.1f mV"%a
print "The negative sign suggests diode in reverse bias"
import math
#Variable declaration
#T1,T2=Temperature in kelvin
#Is1=Reverse saturation current at temperature T1 in ampere
#Is2=Reverse saturation current at temperature T2 in ampere
#Is2=Is1*2^((T2-T1)/10)
#((T2-T1)/10)*log(2)=log(Is2/Is1)
#b=(Is2/Is1)
b=50
#Calculations
a=((10*math.log(b))/math.log(2))#a=(T2-T1)=rise in temperature in degree celcius
#Result
print "T2-T1 = %.1f C"%a
import math
#Variable declaration
V=0.6#V=cutin voltage in V
r=150.#r=forward resistance in ohm
P=200.0*(10**-3)#P=maximum power in Watt
#Calculations&Results
#P=(i^2)*r where i=maximum safe diode current
i=(math.sqrt(P/r))*10**3
print "i=%.1f mA"%i
#i=((Vb/3)-V)/3 by applying KCL
Vb=((3*i)+V)*3#Vb=maximum permissible battery voltage
print "Vb= %.1f V"%Vb
#Incorrect answers in textbook
#Variable declaration
V=15#V=supply voltage
Vz=12#Vz=Zener voltage
P=0.36#P=power of Zener diode
#Calculations&Results
#P=Vz*I
I=(P/Vz)#I=maximum allowable Zener current
print "I= %.2f A"%I
Vr=V-Vz#Vr=voltage drop across series resistance R
print "Vr=%.f V"%Vr
R=Vr/I#R=series resistance
print "R=%.f ohm"%R
#I=Iz+Il
Iz=2*(10**-3)#Iz=minimum diode current
Il=I-Iz#Il=current through load resistance Rl
print "Il=%.f mA"%(Il*10**3)
Rlm=Vz/Il#Rlm=minimum value of Rl
print "Rlm=%.1f ohm"%Rlm
print "The allowable range of variation of Rl is 428.6ohm<=Rl<infinite"
#Variable declaration
V=15#V=supply voltage
Vz=12.#Vz=Zener voltage
P=0.36#P=power of Zener diode
#Calculations&Results
#P=Vz*I
I=(P/Vz)#I=maximum allowable Zener current
print "I=%.2f A"%I
Iz=2*10**(-3)#Iz=minimum value attained by the zener current
Rl=1000#Rl=load resistance
i=Vz/Rl#i=load current
print "i=%.3f A"%i
Imin=Iz+i#Imin=minimum allowable value of current
R=100#R=series resistance
Vr=Imin*R#Vr=voltage drop across R
print "Vr=%.1f V"%Vr
Vmin=Vz+Vr#Vmin=minimum value of V
print "Vmin=%.1f V"%Vmin
I1=I+i
print "I1=%.f mA"%(I1*10**3)
VR=I1*R
print "VR=%.1f V"%VR
Vmax=Vz+VR#Vmax=maximum value of V
print "Vmax=%.1f V"%Vmax
print "V can vary between Vmin & Vmax"
import numpy as np
from numpy.linalg import inv
#Variable declaration
Vz=3#Vz=breakdown voltage of zener diode
Vi=12#Vi=input voltage
V=np.matrix('12;-3')#V=[Vi:-Vz]
R1=1000
R2=1000
R3=500#R1,R2,R3=resistances
#Calculations&Results
R=np.matrix([[R1+R2, -R2],[-R2, R2+R3]])
#solving this matrix on the basis of application of KCL & KVL,we get the values of branch currents I & Iz as I1=[I;Iz]
I1=inv(R)*V
print "I=%.2f mA"%(I1[0]*10**3)
print "Iz=%.f mA"%(I1[1]*10**3)
Pz=Vz*I1[1]#Pz=power dissipated in zener diode
print "Pz=%.f mW"%(Pz*10**3)
print "Power dissipated does not exceed the maximum power limit of 20mW"
#Variable declaration
Vs1=15
Vs2=30.#Vs=supply voltage varying from 15(Vs1) to 30(Vs2) Volt
Vzo=9#Vzo=knee voltage
rZ=5.#rZ=dynamic resistance in ohms
R=800#R=series resistance in ohms
#Calculations&Results
Izmin=(Vs1-Vzo)/(R+rZ)#Izmin=current through zener diode when Vs is 15 V
print "Izmin=%.2f mA"%(Izmin*10**3)
Vomin=(rZ*Izmin)+Vzo#Vomin=corresponding minimum output voltage
print "Vomin=%.3f V"%Vomin
Izmax=(Vs2-Vzo)/(R+rZ)#Izmax=current through zener diode when Vs is 30 V
print "Izmax=%.f mA"%(Izmax*10**3)
Vomax=(rZ*Izmax)+Vzo#Vomax=corresponding maximum output voltage
print "Vomax=%.2f V"%Vomax
print "Output voltage Vo varies in the range Vomin to Vomax"
#Variable declaration
V=35#V=supply voltage
Iz=25*10**(-3)#Iz=diode current
Il=5*10**(-3)#Il=load current
Vzo=7#Vzo=knee voltage of zener diode
rZ=6#rZ=dynamic resistance in ohms
#Calculations&Results
Vz=Vzo+(rZ*Iz)#Vz=zener voltage
print "Vz=%.2f V"%Vz
I=Iz+Il#I=current through resistance R
print "I=%.f mA"%(I*10**3)
R=(V-Vz)/I
print "R=%.1f ohm"%R