# Chapter 4 - Field Effect Transistors¶

## Example 4_1 Page No. 98¶

In :
from __future__ import division
IDSS=10*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current
VP=(-4)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage
VGS=(-2)
print "VGS = %0.2f"%(VGS)," volts" # gate to source voltage
VDSmin=VGS-VP
print "VDSmin  =VGS-VP=%0.2f"%(VDSmin)," volts" # Drain to source voltage
ID=IDSS*(1-VGS/VP)**2
print "ID =IDSS*(1-VGS/VP)**2= %0.2e"%(ID)," ampere" #   drain current

IDSS = 0.01  ampere
VP= -4.00  volts
VGS = -2.00  volts
VDSmin  =VGS-VP=2.00  volts
ID =IDSS*(1-VGS/VP)**2= 2.50e-03  ampere


## Example 4_2 Page No. 99¶

In :
from __future__ import division
IDSS=10*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current
VP=(-4)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage
VGS=(0)
print "VGS = %0.2f"%(VGS)," volts" # gate to source voltage1
RDS=1/((2*(IDSS/(-VP)))*(1-VGS/VP))#formula for JFET
print "RDS = 1/[(2*(IDSS/(-VP)))*(1-VGS/VP)]=%0.2f"%(RDS)," ohm" #   drain to source resistance for VGS=0V
VGS=(-2)
print "VGS = %0.2f"%(VGS)," volts" # gate to source voltage2
RDS=1/((2*(IDSS/(-VP)))*(1-VGS/VP))
print "RDS = 1/[(2*(IDSS/(-VP)))*(1-VGS/VP)]=%0.2f"%(RDS)," ohm" #   drain to source resistance for VGS=(-2)

IDSS = 0.01  ampere
VP= -4.00  volts
VGS = 0.00  volts
RDS = 1/[(2*(IDSS/(-VP)))*(1-VGS/VP)]=200.00  ohm
VGS = -2.00  volts
RDS = 1/[(2*(IDSS/(-VP)))*(1-VGS/VP)]=400.00  ohm


## Example 4_3 Page No. 104¶

In :
from __future__ import division
ID=10*10**(-3)
print "ID = %0.2f"%(ID)," ampere" #  given drain current
VDD=(24)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage
VT=(5)
print "VT= %0.2f"%(VT)," volts" # Threshold voltage
VGS=(10)
print "VGS= %0.2f"%(VGS)," volts" # gate to source voltage1
KF=ID/(VGS-VT)**2
print "KF = ID/(VGS-VT)**2 = %0.2e"%(KF)," A/V**2" # To calculate Scale factor for finding ID2
VDS=(7)
print "VDS =VGS= %0.2f"%(VDS)," volts" # drain to source voltage
VGS=(VDS)
ID=KF*(VGS-VT)**2
print "ID =KF*(VGS-VT)**2= %0.2e"%(ID)," ampere" # New drain current for VDS=24V
RL=(VDD-VDS)/ID
print "RL=(VDD-VDS)/ID= %0.2e"%(RL)+ " ohm"  #calculation for load resistance at VDS=24V

ID = 0.01  ampere
VDD= 24.00  volts
VT= 5.00  volts
VGS= 10.00  volts
KF = ID/(VGS-VT)**2 = 4.00e-04  A/V**2
VDS =VGS= 7.00  volts
ID =KF*(VGS-VT)**2= 1.60e-03  ampere
RL=(VDD-VDS)/ID= 1.06e+04 ohm


## Example 4_4 Page No. 105¶

In :
from math import sqrt
from __future__ import division
print "part(i) "# part(i) of this question
IDSS=5*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current JFET 1
VP=(2)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage for JFET 1
IDQ=4.42*10**(-3)
print "IDQ = %0.2f"%(IDQ)," ampere" #   drain current for JFET 1
gm=((2)*sqrt(IDQ*IDSS))/VP
print "gm =[(2)*sqrt(IDQ*IDSS)]/VP= %0.2e"%(gm)," A/V"# calculating transconductance for JFET with IDQ = 4.42 mA

print "part(ii) "# part(ii) of this question
IDQ=6.04*10**(-3)
print "IDQ = %0.2f"%(IDQ)," ampere" #   drain current for JFET 1
IDSS=15*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current JFET2
VP=(6)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage for JFET2
gm=((2)*sqrt(IDQ*IDSS))/VP
print "gm =[(2)*sqrt(IDQ*IDSS)]/VP= %0.2e"%(gm)," A/V"# calculating transconductance for JFET with IDQ = 6.04 mA

print "part(iii) "# part(iii) of this question
IDQ=1*10**(-3)
print "IDQ = %0.2e"%(IDQ)," ampere" #   drain current for EMOSFET 1
KF=0.25*10**(-3)
print "KF = %0.2e"%(KF)," A/V**2" #  Scale factor for finding EMOSFET1
gm=sqrt(4*IDQ*KF)
print "gm =sqrt(4*IDQ*KF)= %0.2e"%(gm)," A/V"# calculating transconductance for EMOSFET1 with IDQ = 1 mA

print "part(iv) "# part(iv) of this question
IDQ=0.91*10**(-3)
print "IDQ = %0.2e"%(IDQ)," ampere" #   drain current for EMOSFET 2
KF=0.375*10**(-3)
print "KF = %0.2e"%(KF)," A/V**2" #  Scale factor for finding EMOSFET2
gm=sqrt(4*IDQ*KF)
print "gm =sqrt(4*IDQ*KF)= %0.2e"%(gm)," A/V"# calculating transconductance for EMOSFET2 with IDQ = 0.91 mA

part(i)
IDSS = 0.01  ampere
VP= 2.00  volts
IDQ = 0.00  ampere
gm =[(2)*sqrt(IDQ*IDSS)]/VP= 4.70e-03  A/V
part(ii)
IDQ = 0.01  ampere
IDSS = 0.01  ampere
VP= 6.00  volts
gm =[(2)*sqrt(IDQ*IDSS)]/VP= 3.17e-03  A/V
part(iii)
IDQ = 1.00e-03  ampere
KF = 2.50e-04  A/V**2
gm =sqrt(4*IDQ*KF)= 1.00e-03  A/V
part(iv)
IDQ = 9.10e-04  ampere
KF = 3.75e-04  A/V**2
gm =sqrt(4*IDQ*KF)= 1.17e-03  A/V


## Example 4_5 Page No. 106¶

In :
from __future__ import division
IDQmax=5*10**(-3)
print "IDQmax = %0.2f"%(IDQmax)," ampere" #  drain current for JFET for maximum transfer characteristics
IDmax=IDQmax# maximum drain current will be given by IDQmax
IDQmin=3*10**(-3)
print "IDQmin = %0.2f"%(IDQmin)," ampere" #  drain current for JFET for minimum transfer characteristics
VDD=(20)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
VDSmin=(6)
print "VDSmin= %0.2f"%(VDSmin)," volts" # minimum Drain to source voltage supply
ID=2.4*10**(-3)
print "ID = %0.2e"%(ID)," ampere" #  drain current chosen for operation within max and min limits
VGG=3
print "VGG= %0.2f"%(VGG)," volts" # Gate voltage from fig.
Ri=100*10**(3)
print "Ri= %0.2e"%(Ri)+ " ohm"  #eqivalent input resistance
RF=(VGG-0)/(ID-0)
print "RF= (VGG-0)/(ID-0)= %0.2f"%(RF)+ " ohm"  #calculation for  feedback resistance
R1=VDD*Ri/VGG #using formulae VGG=VDD*Ri/R1
print "R1= VDD*Ri/VGG= %0.2e"%(R1)+ " ohm"  #calculation for  first resistance R1 at input side
R2=R1*VGG/(VDD-VGG)
print "R2= R1*VGG/(VDD-VGG)= %0.2e"%(R2)+ " ohm"  #calculation for  second resistance R2 at input side
RL=(((VDD-VDSmin)/IDmax)-RF) # using formulae VDD=IDmax(RL+RF)+VDSmin
print "RL=[((VDD-VDSmin)/IDmax)-RF]=%0.2f"%(RL)+ " ohm"  #Load resistance calculation

IDQmax = 0.01  ampere
IDQmin = 0.00  ampere
VDD= 20.00  volts
VDSmin= 6.00  volts
ID = 2.40e-03  ampere
VGG= 3.00  volts
Ri= 1.00e+05 ohm
RF= (VGG-0)/(ID-0)= 1250.00 ohm
R1= VDD*Ri/VGG= 6.67e+05 ohm
R2= R1*VGG/(VDD-VGG)= 1.18e+05 ohm
RL=[((VDD-VDSmin)/IDmax)-RF]=1550.00 ohm


## Example 4_6 Page No. 107¶

In :
from __future__ import division
IDSS=50*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current JFET
VP=(-10)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage for JFET
VGSQ=(-5)
print "VGSQ= %0.2f"%(VGSQ)," volts" # Gate  operating point voltage
ID=IDSS*(1-VGSQ/VP)**2
print "ID =IDSS*(1-VGS/VP)**2= %0.2f"%(ID)," ampere" #   drain current JFET
RF=abs(VGSQ/ID)
print "RF= (VGSQ)/(ID)= %0.2f"%(RF)+ " ohm"  #calculation for  feedback resistance

IDSS = 0.05  ampere
VP= -10.00  volts
VGSQ= -5.00  volts
ID =IDSS*(1-VGS/VP)**2= 0.01  ampere
RF= (VGSQ)/(ID)= 400.00 ohm


## Example 4_7 Page No. 108¶

In :
from sympy import symbols,solve
from __future__ import division
IDSS=5*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current JFET
RL=910
print "RL= %0.2f"%(RL)+ " ohm"  #Load resistance
RF=2.29*10**(3)
print "RF= %0.2f"%(RF)+ " ohm"  #  feedback resistance
R1=12*10**(6)
print "R1= %0.2e"%(R1)+ " ohm"  # first resistance R1 at input side
R2=8.57*10**(6)
print "R2= %0.2e"%(R2)+ " ohm"  # second resistance R2 at input side
VDD=(24)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
VP=(-2)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage for JFET
VGG=(VDD*R2)/(R1+R2)
print "VGG= VDD*R2/(R1+R2)=%0.2f"%(VGG)," volts" # Gate voltage for JFET
print "Quadratic equation =5.244*ID**(2)-55.76*ID+144=0"#  Forming Quadratic equation using VGS = VGG-ID*RF and ID = IDSS(1-VGS/VP)**2 where ID in mA
p = [5.244,  -55.76,  144]
P=symbols('P')
ID=solve(p*P**2+p*P+p)*10**(-3)# values of ID converted into Ampere  by multiplying by 10**(-3)
print "ID = %0.2f"%(ID)," ampere" #   drain current JFET
print "Since ID <=IDSS, hence ID=6.214 mA cannot be chosen, so we chose ID=4.42 mA"
IDQ=4.42*10**(-3)
print "IDQ =%0.2f"%(IDQ),"  A"#Since ID <=IDSS, hence ID=6.214 mA cannot be chosen, so we chose ID=4.42 mA
VGSQ=VGG-IDQ*RF
print "VGSQ = VGG-IDQ*RF = %0.2f"%(VGSQ)," volts" #  Gate  operating point voltage
VDSQ=VDD-IDQ*(RL+RF)
print "VDSQ= VDD-IDQ*(RL+RF)= %0.2f"%(VDSQ)," volts" # Drain voltage for JFET
VDGQ=VDSQ-VGSQ
print "VDGQ = VDSQ-VGSQ =%0.2f"%(VDGQ)," volts" # Drain-Gate voltage for JFET
print "VDGQ >magnitude_VP,Hence FET is in pinch off region"

IDSS = 0.01  ampere
RL= 910.00 ohm
RF= 2290.00 ohm
R1= 1.20e+07 ohm
R2= 8.57e+06 ohm
VDD= 24.00  volts
VP= -2.00  volts
VGG= VDD*R2/(R1+R2)=10.00  volts
ID = 0.00  ampere
Since ID <=IDSS, hence ID=6.214 mA cannot be chosen, so we chose ID=4.42 mA
IDQ =0.00   A
VGSQ = VGG-IDQ*RF = -0.12  volts
VDSQ= VDD-IDQ*(RL+RF)= 9.86  volts
VDGQ = VDSQ-VGSQ =9.98  volts
VDGQ >magnitude_VP,Hence FET is in pinch off region


## Example 4_8 Page No. 108¶

In :
from sympy import symbols,solve
from __future__ import division
IDSS=15*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current of JFET
RL=910
print "RL= %0.2f"%(RL)+ " ohm"  #Load resistance
RF=2.29*10**(3)
print "RF= %0.2f"%(RF)+ " ohm"  #  feedback resistance
R1=12*10**(6)
print "R1= %0.2e"%(R1)+ " ohm"  # first resistance R1 at input side
R2=8.57*10**(6)
print "R2= %0.2e"%(R2)+ " ohm"  # second resistance R2 at input side
VDD=(24)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
VP=(-6)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage for JFET
VGG=(VDD*R2)/(R1+R2)
print "VGG= VDD*R2/(R1+R2)=%0.2f"%(VGG)," volts" # Gate voltage for JFET
print "Quadratic equation =5.244*ID**(2)-75.68*ID+256=0"# where ID in mA
p = [5.244,  -75.68,  256]
P=symbols('P')
ID=solve(p*P**2+p*P+p)*10**(-3)#values of ID converted into Ampere  by multiplying by 10**(-3)
print "ID = %0.2f"%(ID)," ampere" #   drain current JFET
VDG=VDD-(ID*RL)-VGG
print "VDG= %0.2f"%(VDG)," volts" # Drain-gate voltage for JFET
print "since VDG < magnitude_VP for ID=9.0189 mA which is inappropriate for JFET pinch off region ,hence ID=5.4128 mA is choosen  !"
IDQ=5.41*10**(-3) # since VDG < magnitude_VP for ID=9.0189 mA which is inappropriate for JFET pinch off region ,hence ID=5.4128 mA is choosen  !
print "IDQ =%0.2f"%(IDQ),"  ampere"
VGSQ=VGG-IDQ*RF
print "VGSQ = VGG-IDQ*RF = %0.2f"%(VGSQ)," volts" #  Gate  operating point voltage
VDSQ=VDD-IDQ*(RL+RF)
print "VDSQ= VDD-IDQ*(RL+RF)= %0.2f"%(VDSQ)," volts" # Drain voltage for JFET
VDGQ=VDSQ-VGSQ
print "VDGQ = VDSQ-VGSQ =%0.2f"%(VDGQ)," volts" # Drain-Gate voltage for JFET
print "VDGQ > VP,Hence FET is in pinch off region"

# NOTE :all values of book ans is wrong so give note-INCOMPLETE QUESTION
#Roots for drain current quadratic equation are wrong in the book thus value for VGSQ,VDSQ and VDGQ are also wrong

IDSS = 0.01  ampere
RL= 910.00 ohm
RF= 2290.00 ohm
R1= 1.20e+07 ohm
R2= 8.57e+06 ohm
VDD= 24.00  volts
VP= -6.00  volts
VGG= VDD*R2/(R1+R2)=10.00  volts
ID = 0.01  ampere
VDG= 9.08  volts
since VDG < magnitude_VP for ID=9.0189 mA which is inappropriate for JFET pinch off region ,hence ID=5.4128 mA is choosen  !
IDQ =0.01   ampere
VGSQ = VGG-IDQ*RF = -2.39  volts
VDSQ= VDD-IDQ*(RL+RF)= 6.69  volts
VDGQ = VDSQ-VGSQ =9.08  volts
VDGQ > VP,Hence FET is in pinch off region


## Example 4_9 Page No. 112¶

In :
from sympy import symbols,solve
from __future__ import division
RL=12*10**(3)
print "RL= %0.2f"%(RL)+ " ohm"  #Load resistance
RF=6*10**(3)
print "RF= %0.2f"%(RF)+ " ohm"  #  feedback resistance
R1=12*10**(6)
print "R1= %0.2e"%(R1)+ " ohm"  # first resistance R1 at input side
R2=8.57*10**(6)
print "R2= %0.2e"%(R2)+ " ohm"  # second resistance R2 at input side
VDD=(24)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
VT=(3)
print "VT= %0.2f"%(VT)," volts" # Threshold voltage for n-channel EMOSFET
KF=0.25*10**(-3)
print "KF= %0.2f"%(KF)," A/V**2" # Constant for n-channel EMOSFET
VGG=(VDD*R2)/(R1+R2)
print "VGG= VDD*R2/(R1+R2)=%0.2f"%(VGG)," volts" # Gate voltage for n-channel EMOSFET
print "Quadratic equation =9*ID**(2)-25*ID+16=0"# IDS=KF*(VGS-VT)**2 and VGS=VGG-ID*RD ,so Quadratic equation formed is :IDS=KF*(VGG-ID*RD-VT)**2 where ID in mA
p = [9,  -25,  16]
P=symbols('P')
ID=solve(p*P**2+p*P+p)*10**(-3)#values of ID converted into Ampere  by multiplying by 10**(-3)
print "ID = %0.2f"%(ID)," A" #   drain current n-channel EMOSFET in Ampere
VGS=VGG-ID*RF# For ID=1.78 mA and ID=1mA
print "VGS = VGG-ID*RF = %0.2f"%(VGS)," volts" #  Gate  operating point voltage
print "Since VGS < VT for ID=1.78 mA, hence ID = 1.78 mA cannot be chosen, so we chose ID= 1 mA as operating drain current IDQ"
IDQ=1*10**(-3)
print "IDQ =%0.2f"%(IDQ),"A"#Since VGS < VT for ID=1.78 mA, hence ID = 1.78 mA cannot be chosen, so we chose ID= 1 mA as operating drain current IDQ
VGSQ=VGG-IDQ*RF
print "VGSQ = VGG-IDQ*RF = %0.2f"%(VGSQ)," volts" #  Gate  operating point voltage
VDSQ=VDD-IDQ*(RL+RF)
print "VDSQ= VDD-IDQ*(RL+RF)= %0.2f"%(VDSQ)," volts" # Drain voltage for n-channel EMOSFET
# NOTE:Value of VGS= -0.6676390 volts for ID=1.78 mA but in book given as -0.68 V

RL= 12000.00 ohm
RF= 6000.00 ohm
R1= 1.20e+07 ohm
R2= 8.57e+06 ohm
VDD= 24.00  volts
VT= 3.00  volts
KF= 0.00  A/V**2
VGG= VDD*R2/(R1+R2)=10.00  volts
ID = 0.00  A
VGS = VGG-ID*RF = 4.00  volts
Since VGS < VT for ID=1.78 mA, hence ID = 1.78 mA cannot be chosen, so we chose ID= 1 mA as operating drain current IDQ
IDQ =0.00 A
VGSQ = VGG-IDQ*RF = 4.00  volts
VDSQ= VDD-IDQ*(RL+RF)= 6.00  volts


## Example 4_10 Page No. 113¶

In :
from math import sqrt
from __future__ import division
RL=12*10**(3)
print "RL= %0.2f"%(RL)+ " ohm"  #Load resistance
RF=6*10**(3)
print "RF= %0.2f"%(RF)+ " ohm"  #  feedback resistance
R1=12*10**(6)
print "R1= %0.2e"%(R1)+ " ohm"  # first resistance R1 at input side
R2=8.57*10**(6)
print "R2= %0.2e"%(R2)+ " ohm"  # second resistance R2 at input side
VDD=(24)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
VT=(3)
print "VT= %0.2f"%(VT)," volts" # Threshold voltage for n-channel EMOSFET
KF=0.375*10**(-3)
print "KF= %0.2f"%(KF)," A/V**2" # Constant for  n-channel EMOSFET
VGG=(VDD*R2)/(R1+R2)
print "VGG= VDD*R2/(R1+R2)=%0.2f"%(VGG)," volts" # Gate voltage for  n-channel EMOSFET
print "Quadratic equation =36*ID**(2)-86.67*ID+49=0"# IDS=KF*(VGS-VT)**2 and VGS=VGG-ID*RD ,so Quadratic equation formed is :IDS=KF*(VGG-ID*RD-VT)**2 ,where ID in mA
p = [36,  -86.67,  49]
P=symbols('P')
ID=solve(p*P**2+p*P+p)*10**(-3)#values of ID converted into Ampere  by multiplying by 10**(-3)
print "ID = %0.2f"%(ID)," A" #   drain current n-channel EMOSFET in Ampere
VGS=VGG-ID*RF#  Gate voltage for ID = 1.5 mA and ID = 0.91 mA
print "VGS = VGG-ID*RF = %0.2f"%(VGS)," volts" #  Gate voltage
print "Since VGS < VT for ID=1.5 mA, hence ID = 1.5 mA cannot be chosen, so we chose ID= 0.91 mA as operating drain current IDQ"
IDQ=0.91*10**(-3)
print "IDQ =%0.2f"%(IDQ)," A"#Since VGS < VT for ID=1.5 mA, hence ID = 1.5 mA cannot be chosen, so we chose ID= 0.91 mA as operating drain current IDQ
change_IDQ=((1-0.91)*100)/(1)#
print "change in IDQ = %0.2f"%(change_IDQ)," percent"# Percent change in IDQ from value 1 mA from its actual value IDQ=0.91mA
VGSQ=VGG-IDQ*RF
print "VGSQ = VGG-IDQ*RF = %0.2f"%(VGSQ)," volts" #  Gate  operating point voltage
VDSQ=VDD-IDQ*(RL+RF)
print "VDSQ= VDD-IDQ*(RL+RF)= %0.2f"%(VDSQ)," volts" # Drain voltage for n-channel EMOSFET

# note: in the textbook author has given KF = .375 but I have work with KF = .375*10**-3A/V**2

RL= 12000.00 ohm
RF= 6000.00 ohm
R1= 1.20e+07 ohm
R2= 8.57e+06 ohm
VDD= 24.00  volts
VT= 3.00  volts
KF= 0.00  A/V**2
VGG= VDD*R2/(R1+R2)=10.00  volts
ID = 0.00  A
VGS = VGG-ID*RF = 4.56  volts
Since VGS < VT for ID=1.5 mA, hence ID = 1.5 mA cannot be chosen, so we chose ID= 0.91 mA as operating drain current IDQ
IDQ =0.00  A
change in IDQ = 9.00  percent
VGSQ = VGG-IDQ*RF = 4.54  volts
VDSQ= VDD-IDQ*(RL+RF)= 7.62  volts


## Example 4_11 Page No. 114¶

In :
from math import sqrt
from sympy import symbols,solve
from __future__ import division
RF=6*10**(3)
print "RF= %0.2f"%(RF)+ " ohm"  #  feedback resistance
VDD=(20)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
print "part(i) "# part(i) of this question
VT=(2)
print "VT= %0.2f"%(VT)," volts" # Threshold voltage for EMOSFET
KF=0.25*10**(-3)
print "KF= %0.2f"%(KF)," A/V**2" # Constant for EMOSFET
ID=1*10**(-3)
print "ID = %0.2f"%(ID)," A" #   drain current EMOSFET in Ampere
RL=(VDD-VT-sqrt(ID/KF))/ID # Using formulae ID=KF*(VDD-ID*RL-VT)
print "RL=[VDD-VT-sqrt(ID/KF)]/ID= %0.2f"%(RL)+ " ohm"  #Load resistance
print "part(ii) "# part(ii) of this question
VT=(3)
print "VT= %0.2f"%(VT)," volts" # Threshold voltage for EMOSFET
KF=0.375*10**(-3)
print "KF= %0.2f"%(KF)," A/V**2" # Constant for EMOSFET
print "Quadratic equation =(256)*ID**(2)-(546.67)*ID+289=0"#IDS=KF*(VGS-VT)**2 =KF*(VDS-VT)**2 and VDS=VDD-ID*RL,so Quadratic equation  is:IDS=KF*(VDD-ID*RL-VT)**2 ,where ID in mA
p = [256,  -546.66 , 289]
P=symbols('P')
ID=solve(p*P**2+p*P+p)*10**(-3)#values of ID converted into Ampere  by multiplying by 10**(-3)
print "ID = %0.2f"%(ID)," A" #   drain current EMOSFET in Ampere
VDS=VDD-ID*RL# Drain voltage for ID = 1.173 mA and ID = 0.962 mA
print "VDS =VDD-ID*RL = %0.2f"%(VDS)," volts" #  Drain voltage
IDQ=0.962*10**(-3)
print "IDQ =%0.2f"%(IDQ)," A"#Since VDS < VT for ID=1.173 mA, hence ID = 1.173 mA cannot be chosen, so we chose ID= 0.962 mA as operating drain current IDQ
Percentage_change=((1-0.962)*100)/(1)
print "Percentage change= %0.2f"%(Percentage_change)," percent"# Percent change in IDQ  value from 1 mA(part(i)) to its  value ( of part(ii))IDQ=0.91mA
# NOTE: part(ii):the values of ID = 1.173 mA or ID = 0.962 mA but in book given as ID= 1.197 mA and ID = 0.939 mA .Hence (correct) Percentage_change in ID= 3.8 % but in book given as 6.1 %
# ANS is not correct check &correct

RF= 6000.00 ohm
VDD= 20.00  volts
part(i)
VT= 2.00  volts
KF= 0.00  A/V**2
ID = 0.00  A
RL=[VDD-VT-sqrt(ID/KF)]/ID= 16000.00 ohm
part(ii)
VT= 3.00  volts
KF= 0.00  A/V**2
ID = 0.00  A
VDS =VDD-ID*RL = 4.60  volts
IDQ =0.00  A
Percentage change= 3.80  percent


## Example 4_12 Page No. 115¶

In :
from __future__ import division
VDD=(5)
print "VDD= %0.2f"%(VDD)," volts" # Drain voltage supply
RL1=125*10**(3)
print "RL1= %0.2e"%(RL1)+ " ohm"  #Load resistance
RL2=200*10**(3)
print "RL2= %0.2e"%(RL2)+ " ohm"  #Load resistance
IDON1=34.88*10**(-6)
print "IDON1 =%0.2f"%(IDON1)," A"#Drain current for load line 1 from fig.
IDON2=22.5*10**(-6)
print "IDON2 =%0.2f"%(IDON2)," A"#Drain current for load line 2 from fig.
VDON1=VDD-IDON1*RL1
print "VDON1=VDD-IDON1*RL1= %0.2f"%(VDON1)," volts" #  output voltage  at drain terminal for IDON1
VDON2=VDD-IDON2*RL2
print "VDON2=VDD-IDON2*RL2= %0.2f"%(VDON2)," volts" #  output voltage  at drain terminal for IDON2

VDD= 5.00  volts
RL1= 1.25e+05 ohm
RL2= 2.00e+05 ohm
IDON1 =0.00  A
IDON2 =0.00  A
VDON1=VDD-IDON1*RL1= 0.64  volts
VDON2=VDD-IDON2*RL2= 0.50  volts


## Example 4_13 Page No. 120¶

In :
from __future__ import division
IDSS=10*10**(-3)
print "IDSS = %0.2f"%(IDSS)," ampere" #  maximum drain current for n-channel DEMOSFET
ID=IDSS # since VGS=0V, so ID=maximum
VP=(-4)
print "VP= %0.2f"%(VP)," volts" # pinch off voltage
VGS=(0)
print "VGS= %0.2f"%(VGS)," volts" # Gate to source voltage
VDD=(10)
print "VDD= %0.2f"%(VDD)," volts" # Drain supply voltage
RL=0.5*10**(3)
print "RL= %0.2f"%(RL)+ " ohm"  #Load resistance
VDS=VDD-ID*RL
print "VDS=VDD-ID*RL= %0.2f"%(VDS)," volts" # Drain to source  voltage ,since VDS>VP DEMOSFET is in pinch off
print "VDS>VP,so pinch off region"
RL=0.75*10**(3)
print "RL= %0.2f"%(RL)+ " ohm"  # New Load resistance value
VDS=VDD-ID*RL
print "VDS=VDD-ID*RL= %0.2f"%(VDS)," volts" # New Drain to source  voltage for RL=750 ohm
print "VDS<VP,so ohmic region"# since VDS < VP DEMOSFET is in ohmic region for RL=750 ohm and hence will not operate as a current source

IDSS = 0.01  ampere
VP= -4.00  volts
VGS= 0.00  volts
VDD= 10.00  volts
RL= 500.00 ohm
VDS=VDD-ID*RL= 5.00  volts
VDS>VP,so pinch off region
RL= 750.00 ohm
VDS=VDD-ID*RL= 2.50  volts
VDS<VP,so ohmic region


## Example 4_14 Page No. 122¶

In :
from math import sqrt
from __future__ import division
KF1=0.25*10**(-3)
print "KF1 = %0.2e"%(KF1)," A/V**2" #  Scale factor
KF2=KF1
print "KF2 = %0.2e"%(KF2)," A/V**2" #  Scale factor
IQ=1*10**(-3)
print "IQ= %0.2e"%(IQ)," ampere" # constant current  source value
VT1=2
print "VT1 = %0.2f"%(VT1)," volts"# Threshold voltage
VT2=VT1
print "VT2 = %0.2f"%(VT2)," volts"# Threshold voltage
VDD=(15)
print "VDD= %0.2f"%(VDD)," volts" # Drain supply voltage
IREF=IQ
print "IREF =IQ= %0.2e"%(IREF)," ampere" # Reference current value
VGS=VT1+sqrt(2*IREF/KF1) # Formulae
print "VGS= VT1+sqrt(2*IREF/KF1)=%0.2f"%(VGS)," volts" # Gate to source voltage
R=(VDD-VGS)/IREF
print "R= (VDD-VGS)/IREF=%0.2f"%(R)+ " ohm"  # resistance value to obtain constant current
#  ERROR NOTE:values of VGS and R (correct) are 4.8284271 volts and 10171.573 ohm  respectively but given in book are VGS=4V and R=11 kilo ohms

KF1 = 2.50e-04  A/V**2
KF2 = 2.50e-04  A/V**2
IQ= 1.00e-03  ampere
VT1 = 2.00  volts
VT2 = 2.00  volts
VDD= 15.00  volts
IREF =IQ= 1.00e-03  ampere
VGS= VT1+sqrt(2*IREF/KF1)=4.83  volts
R= (VDD-VGS)/IREF=10171.57 ohm


## Example 4_15 Page No. 123¶

In :
from math import log10
from __future__ import division
RON=100
print "RON= %0.2f"%(RON)+ " ohm"  #ON resistance of  analog series switch
ROFF=10**(10)
print "ROFF= %0.2e"%(ROFF)+ " ohm"  #OFF resistance analog series switch
Vip=1
print "Vip= %0.2f"%(Vip)," volts"# Peak amplitude of analog voltage
Rs=100
print "Rs= %0.2f"%(Rs)+ " ohm"  #Voltage source resistance
RL=10*10**(3)
print "RL= %0.2f"%(RL)+ " ohm"  #Load resistance
print "part(i) "# part(i) of this question
Vo=(Vip*RL)/(RL+RON+Rs)
print "Vo=(Vip*RL)/(RL+RON+Rs)= %0.2f"%(Vo)," volts"# ON voltage
ErON=(Vip*(RON+Rs)/(RL+RON+Rs))*100
print "ErON=[Vip*(RON+Rs)/(RL+RON+Rs)]*100= %0.2f"%(ErON)," percent"# Output voltage error
vOFF=(Vip*RL)/ROFF
print "vOFF=(Vip*RL)/ROFF= %0.2f"%(vOFF)," volts"# Output voltage in OFF state
OFF_isolation=20*log10(Vip/vOFF)
print "OFF_isolation=20*log10(Vip/vOFF)= %0.2f"%(OFF_isolation)," dB" # OFF_isolation=20*log10(Vip/vOFF) in dB# Thus ON error and OFF isolation decrease with increasing values of RL.
print "part(ii) "# part(ii) of this question
vOFF=(Vip*RON)/(Rs+RON)
print "vOFF=(Vip*RON)/(Rs+RON)= %0.2f"%(vOFF)," volts"# Output voltage in OFF state for analog shunt switch
OFF_isolation=20*log10((Rs+RON)/RON)# OFF_isolation of shunt switch
print "OFF_isolation=20*log10((Rs+RON)/RON)= %0.2f"%(OFF_isolation)," dB"# Thus shunt switch is inferior to series switch in its OFF isolation property

# ERROR NOTE: in question the author has given RL = 10K but in solution he has used RL = 1 k ... I have done programming using RL = 10 K.

RON= 100.00 ohm
ROFF= 1.00e+10 ohm
Vip= 1.00  volts
Rs= 100.00 ohm
RL= 10000.00 ohm
part(i)
Vo=(Vip*RL)/(RL+RON+Rs)= 0.98  volts
ErON=[Vip*(RON+Rs)/(RL+RON+Rs)]*100= 1.96  percent
vOFF=(Vip*RL)/ROFF= 0.00  volts
OFF_isolation=20*log10(Vip/vOFF)= 120.00  dB
part(ii)
vOFF=(Vip*RON)/(Rs+RON)= 0.50  volts
OFF_isolation=20*log10((Rs+RON)/RON)= 6.02  dB