# drain resistance transconductance and amplification factor
import math
from array import array
#Variable declaration
Vgs=array('d', [0.0, 0.0, 0.3]) #in V
Vds=array('d',[5.0, 10.0, 10.0]) #in V
Id=array('d',[8.0, 8.2, 7.6]) #in mA
#Calcualtions
dVds=Vds[1]-Vds[0] #in V
dId=Id[1]-Id[0] #in mA
rd=(dVds/dId) #in kilo-ohm
dVgs=Vgs[2]-Vgs[1] #in V
dId1=Id[1]-Id[2] #in mA
gm=dId1/dVgs #in mA/volt
mu=gm*rd #A/V
#Result
print("(i) A.C. Drain resistance is ,(kilo-ohm)= %.f"%rd)
print("(ii) Transconductance is ,(mS) = %.f"%gm)
print("(iii) Amplification factor is , = %.f"%mu)
#Transconductance and Amplification factor are calculated wrong in the textbook
# mutual conductance
import math
#Variable declaration
I1=1.0 # in mA
I2=1.2 # in mA
V1=-3.0 # in V
V2=-2.9 # in V
#Calculations
del_ID=(I2-I1)
del_VGS=V2-V1 # in V
gm=del_ID/del_VGS
#Result
print("mutual conductance,gm(mS) = %.f"%gm)
# pinch off voltage
import math
#Variable declaration
a=5.6*10**-6/2 # channel width in m
epsilon0=8.86*10**-12 # in F/m
epsilon=12*epsilon0 # in F/m
Nd=10**21 # in m^-3
e=1.6*10**-19 # in V
#Calculations
Vp=e*Nd*a**2/(2*epsilon);
#Result
print("Pinch off voltage,Vp(V) = %.1f"%Vp)
# ID gm and gmo
import math
#Variable declaration
I_DES=8.7 # in mA
V1=-3.0 # in V
V_GS=-1.0 # in V
#Calculations
gmo=-(2*I_DES/V1)
ID=I_DES*(1-(V_GS/V1))**2
gm=gmo*(1-(V_GS/V1));
#Result
print("(i). ID(mA) = %.3f"%(math.floor(ID*1000)/1000))
print("(ii). gmo(mS) = %.1f"%gmo)
print("(iii).gm(mA) = %.3f"%(math.floor(gm*1000)/1000))
# Vgs
import math
#Variable declaration
ID=3.0 # in mA
I_DSS=9.0 # in mA
Vp=-4.5 # in V
#Calculations
Vgs=-Vp*(math.sqrt(ID/I_DSS)-1)
#Result
print("Vgs(V) = %.1f"%Vgs)
# voltage amplification
import math
#Variable declaration
gm=3 #Transconductance in mS
rl=10 #load resistance in kilo-ohm
#Calculations
av=gm*rl
#Result
print("the voltage aplification is ,= %.f"%av)
# output voltage
import math
#Variable declaration
Rl=20.0 #in kilo-ohm
Rs=1.0 #in kilo-ohm
Rg=1.0 #in M-ohm
Cs=25.0 #in micro-F
mu=20.0 #amplification factor
rd=100.0 #in kilo-ohm
vi=2.0 #in V
f=1.0 #in kilo-Hz
#Calculations
Xc=((1/(2*math.pi*f*10**3*Cs*10**-6)))
A=((mu*Rl*10**3)/((rd+Rl)*10**3))
Vo=A*vi
#Result
print("amplifier output signal voltage is ,(V)= %.2f"%(math.floor(Vo*100)/100))