import math
##Example 5.1
Vtn=0.75;##(V)
W=40.*10**-6;##(cm)
L=4.*10**-6;##(cm)
u=650.;##(cm)
Iox=450.*10**-11;
e=3.9*8.86*10**-14;
Kn=W*u*e/(2.*L*Iox);
print"%s %.2f %s"%('\nconduction parameter= ',Kn,' mA/V^2\n')
Vgs=2.*Vtn;
i_D=Kn*(Vgs-Vtn)**2;
print"%s %.2f %s"%('\ndrain current= ',i_D,' mA\n')
import math
##Example 5.2
Kp=0.2;##(mA/V^2)
Vtp=0.5;
iD=0.5;
Vsg=math.sqrt(iD/Kp)-Vtp;
print"%s %.2f %s"%('\nVgs= ',Vsg,' V\n')
##to bias in p channel MOSFET
Vsd=Vsg+Vtp;
print"%s %.2f %s"%('\nVsd= ',Vsd,' V\n')
import math
##Example 5.3
R1=30.;
R2=20.;
RD=20.;
Vdd=5.;
Vtn=1.;
Kn=0.1;
Vgs=R2*Vdd/(R1+R2);
print"%s %.2f %s"%('\nVgs= ',Vgs,' V\n')
I_D=Kn*(Vgs-Vtn)**2;
print"%s %.2f %s"%('\nthe drain current= ',I_D,' mA\n')
Vds=Vdd-I_D*RD;
print"%s %.2f %s"%('\ndrain to source voltage= ',Vds,' V\n')
import math
##Example 5.4
R1=50.;
R2=50.;
RD=7.5;
Vdd=5.;
Vtp=-0.8;
Vg=2.5;
Kp=0.2;
Vo=R2*Vdd/(R1+R2);
print"%s %.2f %s"%('\nVo= ',Vo,' V\n')
Vsg=Vdd-Vg;
print"%s %.2f %s"%('\nsource to gate voltage= ',Vsg,' V\n')
I_D=Kp*(Vsg+Vtp)**2;
print"%s %.2f %s"%('\nthe drain current= ',I_D,' mA\n')
Vsd=Vdd-I_D*RD;
print"%s %.2f %s"%('\nsource to drain voltage= ',Vsd,' V\n')
import math
##Example 5.6
Vtn=2.;
Kn=80.*10**-3;
##x=W/L
x=4.;
I_D=0.5;
##I_D=Kn*x*((Vgs-Vtn)^2)/2;
Vgs=math.sqrt(I_D*2./(Kn*x))+2.;
print"%s %.2f %s"%('\nVgs= ',Vgs,' V\n')
##y=R1+R2
Rs=2.;
y=10./0.05;
print"%s %.2f %s"%('\nR1+R2= ',y,' Kohm\n')
##Vgs=Vg-Vs=(R2/(R1+R2)*10-5)-I_D*Rs+5
R2=(y/10.)*(Vgs+I_D*Rs);
print"%s %.2f %s"%('\nR2= ',R2,' KOhm\n')
R1=y-R2;
print"%s %.2f %s"%('\nR1= ',R1,' KOhm\n')
import math
##Example 5.7
Vtn=0.8;
Kn=80.;
##x=W/L
x=3.;
I_D=250.;
Vd=2.5;
##I_D=Kn/2*x*(Vgs-Vtn)^2
Vgs=math.sqrt(I_D*2./(Kn*x))+Vtn;
print"%s %.2f %s"%('\nVgs= ',Vgs,' V\n')
Vs=-Vgs
##I_D=(5-Vd)/Rd
Rd=(5.-Vd)/I_D;
print"%s %.2f %s"%('\nRd= ',Rd,' KOhm\n')
Vds=Vd-Vs;
print"%s %.2f %s"%('\nVds= ',Vds,' V\n')
Vdssat=Vgs-Vtn
##since Vds>Vdssat transistor is biased in saturation region
import math
from numpy import roots
##Example 5.8
Vtn=0.8;
Kn=0.05;
##I_D=Kn*(Vgs-Vtn)^2
##Vds=Vgs=5-I_D*Rs
##combining these two equations we obtain 0.5(Vgs)^2+0.2Vgs-4.68
import numpy
from numpy.polynomial import Polynomial as P
p = P([1, 5, 6])
p.roots()
print('',p.roots(),' V\n')
##assuming transistor is conducting ,Vgs must be greater than threshold voltage
Vgs=2.87;
I_D=Kn*(Vgs-Vtn)**2;
print"%s %.2f %s"%('\ndrain current= ',I_D,' mA\n')
#ans is varying due to round of error in book calculations are done wrong
import math
##Example 5.10
Vtn=-2.;
Kn=0.1;
Vdd=5.;
Rs=5.;
Vgs=0.;
I_D=Kn*(Vgs-Vtn)**2;
print"%s %.2f %s"%('\ndrain current= ',I_D,' mA\n')
Vds=Vdd-I_D*Rs;
print"%s %.2f %s"%('\ndc drain to source voltage= ',Vds,' V\n')
Vdssat=Vgs-Vtn
##since Vds>Vdssat transisyor is biased in saturation region
import math
import numpy
##Example 5.11
Vtnd=1;
Vtnl=-2;
Knd=50;
Knl=10;
Vt=5;
import numpy
from numpy.polynomial import Polynomial as P
p = P([4, -40, 5])
p.roots()
print('\npossible solutions ::',p.roots(),'')
##since output voltage cannot be greater than supply voltage 5V
Vo=0.1;##(V)
I_D=Knl*(-Vtnl)**2;
print"%s %.2f %s"%('\ndrain current= ',I_D,' microA\n')
import math
#calculate the
##Example 5.13
Kn1=0.2;
Kn2=0.1;
Kn3=0.1;
Kn4=0.1;
Vtn1=1.;
Vtn2=1.;
Vtn3=1.;
Vtn4=1.;
V2=-5.;
Vgs3=(math.sqrt(Kn4/Kn3)*(-V2-Vtn4)+Vtn3)/(1.+math.sqrt(Kn4/Kn3));
print"%s %.2f %s"%('\nVgs3= ',Vgs3,' V\n')
Iq=Kn3*(Vgs3-Vtn3)**2;
print"%s %.2f %s"%('\nbias current= ',Iq,' mA\n')
Vgs1=math.sqrt(Iq/Kn1)+Vtn1;
print"%s %.2f %s"%('\ngate to source voltage on M1= ',Vgs1,' V\n')
Vds2=-V2-Vgs1;
print"%s %.2f %s"%('\ndrain to source voltage on M2= ',Vds2,' V\n')
Vgs2=Vgs3;
Vdssat=Vgs2-Vtn2
##since Vds2>Vdssat M2 is biased in saturation region
import math
##Example 5.14
I_D=0.5;
Vds=6.;
Kn=80.*10**-6;
Vgs=5.;
Vtn=1.;
##x=W/L
x=I_D*2./(Kn*(Vgs-Vtn)**2);
print(x,"W/L ")
##maximum power dissipation in transistor
Pmax=Vds*I_D;
print"%s %.2f %s"%('\nmaximum power dissipation in transistor= ',Pmax,' W\n')
import math
import numpy
##Example 5.16
Idss=2.;##(mA) saturation current
Vp=-3.5;##(V) pinch off voltage
Vgs=numpy.array([[0, Vp/4. ,Vp/2.]])
I_D=Idss*(1.-Vgs/Vp)**2;
print (I_D)
Vds=Vgs-Vp;
print (Vds)
import math
##Example 5.17
Idss=5.;##mA
Vp=-4.;
Vdd=10.;
I_D=2.;
Vds=6.;
##I_D=Idss*(1-Vgs/Vp)^2
Vgs=(1.-math.sqrt(I_D/Idss))*Vp;
print"%s %.2f %s"%('\nVgs= ',Vgs,' V\n')
Rs=-Vgs/I_D;
print"%s %.2f %s"%('\nRs= ',Rs,' KOhm\n')
Rd=(Vdd-Vds-I_D*Rs)/I_D;
print"%s %.2f %s"%('\nRd= ',Rd,' KOhm\n')
Vgs-Vp
##since Vds>Vgs-Vp JFET is biased in saturation
import math
##Example 5.19
Idss=2.5;
Vp=2.5;
I_D=0.8;
##I_D=Iq=0.8*10^-3=(Vd-(-9))/Rd
Vd=0.8*4.-9;
print"%s %.2f %s"%('\nVd = ',Vd,'V\n')
##I_D=Idss*(1-Vgs/Vp)^2;
Vgs=(1.-math.sqrt(I_D/Idss))*Vp;
print"%s %.2f %s"%('\nVgs = ',Vgs,'V\n')
Vs=1-Vgs;
print"%s %.2f %s"%('\nVs= ',Vs,' V\n')
Vsd=Vs-Vd;
print"%s %.2f %s"%('\nVsd= ',Vsd,' V\n')
Vp-Vgs
##since Vsd>Vp-Vgs JFET is biased in saturation
import math
##Example 5.20
Vtn=0.24;
Kn=1.1;
##x=R1+R2=50000
x=50.;
Vgs=0.5;
Vds=2.5;
Vdd=4.;
Rd=6.7;
I_D=Kn*(Vgs-Vtn)**2;
print"%s %.2f %s"%('\ndrain current= ',I_D,' mA\n')
Vd=Vdd-I_D*Rd;
print"%s %.2f %s"%('\nvoltage at drain= ',Vd,' V\n')
Vs=Vd-Vds;
print"%s %.2f %s"%('\nvoltage at source = ',Vs,'V\n')
Rs=Vs/I_D;
print"%s %.2f %s"%('\nsource resistance = ',Rs,'KOhm\n')
Vg=Vgs+Vs;
print"%s %.2f %s"%('\nvoltage at the gate= ',Vg,' V\n')
##Vg=R2*Vdd/(R2+R1)
R2=Vg*x/Vdd;
print"%s %.2f %s"%('\nR2= ',R2,' KOhm\n')
R1=x-R2;
print"%s %.2f %s"%('\nR1= ',R1,' KOhm\n')
Vgs-Vtn
##since Vds>Vgs-Vtn transistor is biased in saturation