import math
#calculate the
##Example 1.1
T=300.;##((K)temperature)
##for silicon
B=5.23*10**(15);##Constant (per centimeter cube degree kelvin)
Eg=1.1;##bandgap energy in electrovolt(eV)
k=86.*10**(-6);##Boltzmann's constant(eV per degree kelvin)
n_i=B*T**(3/2.)*math.exp(-Eg/(2.*k*T));##intrinsic carrier concentration
print"%s %.2f %s"%('intrinsic carrier concentration= ',n_i,' cm^-3');
import math
#calculate the
##Example 1.2
T=300.;##(K)Given Temperature
Nd=10**16;##(cm^-3)Donor concentration
n_i=1.5*10**10;##(cm^-3)intrinsic carrier concentration
##since Nd>>n_i
n_o=10**16;##(cm^-3)electron concentration
##by using formula ::n_i^2=n_o*p_o
p_o=(n_i)**2/Nd;##hole concentration
print"%s %.2e %s"%('\nelectron concentration= ',n_o,' cm^-3');
print"%s %.2e %s"%('\nhole concentration = ',p_o,' cm^-3');
import math
#calculate the
##Example1.3
T=300;##(K)Given Temperature
Na=10**16;##(cm^-3)Acceptor concentration in p region
Nd=10**17;##(cm^-3)Donor concentration in n region
n_i=1.5*10**10;##(cm^-3)intrinsic carrier concentration
V_T=0.026;##(Volt)terminal voltage
##built-in potential
V_bi=V_T*math.log(Na*Nd/(n_i)**2);
print"%s %.2f %s"%('\nthe built-in potential= ',V_bi,'V')
import math
#calculate the
##Example 1.4
T=300.;##(K)Given Temperature
Na=10**16;##(cm**-3)Acceptor concentration in p region
Nd=10**15;##(cm**-3)Donor concentration in n region
n_i=1.5*10**10;##(cm**-3)intrinsic carrier concentration
C_jo=0.5;##(pF)junction capacitance at zero applied voltage
V_T=0.026;##(Volt)terminal voltage
##built-in potential
V_bi=V_T*math.log(Na*Nd/(n_i)**2);
print"%s %.2f %s"%("the built-in potential(V)",V_bi,"")
##the junction capacitance for
V_R=1.;##(V)reverse bias voltage
Cj=C_jo*(1.+V_R/V_bi)**(-1/2.);
print"%s %.2f %s"%('\nthe junction capacitance for V_R=1V= ',Cj,' pF\n')
V_R=5.;##(V)reverse bias voltage
Cj=C_jo*(1.+V_R/V_bi)**(-1/2.);
print"%s %.2f %s"%('\nthe junction capacitance for V_R=5V = ',Cj,' pF')
import math
#calculate the
##Example 1.5
T=300.;##(K)Given Temperature
V_T=0.026;##(Volt)terminal voltage
Is=10**-11;##(mA)reverse bias saturation current
n=1.;##emission coefficient
v_D=+0.7;##(V)applied voltage
##pn junction is forward biased
i_D=Is*(math.exp(v_D/V_T)-1.);##diode current
print"%s %.2f %s"%('\ndiode current= ',i_D,' mA\n')
v_D=-0.7;##(V)pn junction is reverse biased
Is=10**-14##A;
i_D=Is*(math.exp(v_D/V_T)-1);##diode current
print"%s %.2e %s"%('\ndiode current= ',i_D,' A')
import math
#calculate the
##Example 1.6
Is=10**-13;##(A)reverse saturation current
V_PS=5.;##(V)applied voltage
R=2;##(KOhm)Resistance in circuit
V_T=0.026;##(Volt)terminal voltage
##V_PS=Is*R*(exp(V_D/V_T)-1)+V_D
##5=(10^-13)*(2000)*(exp(V_D/V_T)-1)+V_D
##let right side of equation be x=(10^-13)*(2000)*(exp(V_D/V_T)-1)+V_D
V_D=0.6;##(V)
x=(10**-13)*(2000.)*(math.exp(V_D/V_T)-1.)+V_D
##so the equation is not balanced
V_D=0.65;##(V)
x=(10**-13)*(2000.)*(math.exp(V_D/V_T)-1.)+V_D
##again equation is not balanced .solution for V_D is between 0.6V and 0.65V
V_D=0.619;##(V)
x=(10**-13)*(2000.)*(math.exp(V_D/V_T)-1.)+V_D
##essentially equal to the value of the left side of the equation i.e 5V
print"%s %.2f %s"%('\ndiode voltage= ',V_D,' V')
I_D=(V_PS-V_D)/R;##(A)diode current
print"%s %.2f %s"%('\nthe diode current= ',I_D,' mA')
import math
#calculate the
##Example 1.7
##piecewise linear diode parameters
V_Y=0.6;##(V)
r_f=0.010;##(KOhm)
V_PS=5.;##(V)applied voltage
R=2.;##(KOhm)Resistance in circuit
I_D=(V_PS-V_Y)/(R+r_f);##(A)diode current
print"%s %.2f %s"%('\nthe diode current= ',I_D,' mA\n')
V_D=V_Y+I_D*r_f;##(V)diode voltage
print"%s %.2f %s"%('\ndiode voltage= ',V_D,' V')
import math
#calculate the
##Example 1.9
##circuit and diode parameters
V_PS=5.;##(V)
R=5;##(KOhm)
V_Y=0.6;##(V)
V_T=0.026;##(Volt)terminal voltage
v_i=0.1##*sin(wt)Volt
##dc analysis
I_DQ=(V_PS-V_Y)/R;
print"%s %.2f %s"%('\ndc quiescent current= ',I_DQ,' mA\n')
V_O=I_DQ*R;
print"%s %.2f %s"%('\ndc output voltage= ',V_O,' V\n')
##ac analysis
V_PS=0.;
##Kirchhoff voltage law equation becomes
##v_i=i_d*r_d+i_d*R
r_d=V_T/I_DQ##(Ohm)small signal diode diffusion resistance
i_d=v_i/(r_d+R);##ac diode current
print"%s %.2f %s"%('\nac diode current= ',i_d,'sin(wt) A\n')
v_o=i_d*R;##ac output voltage
print"%s %.2f %s"%('\nac output voltage= ',v_o,'sin(wt) V')
import math
#calculate the
##Example 1.10
V_Y=0.7;##(V)cut in voltage for pn junction
r_f=0.;
V_PS=4;##(V)
R1=4.
R2=4.##(KOhm) from given circuit
I1=(V_PS-V_Y)/R1;
print"%s %.2f %s"%('\ncurrent through pn junction diode= ',I1,' mA\n')
V_Y=0.3;##(V)cut in voltage for Schottky diode
I2=(V_PS-V_Y)/R2;
print"%s %.2f %s"%('\ncurrent through Schottky diode= ',I2,' mA\n')
import math
#calculate the
##Example 1.11
V_Z=5.6;##(V)Zener diode breakdown voltage
r_z=0.;##(Ohm)Zener resistance
I=3.;##(mA)current in the diode
V_PS=10.;##(V)
##I=(V_PS-V_Z)/R
R=(V_PS-V_Z)/I;
print"%s %.2f %s"%('\nresistance= ',R,' KOhm\n')