In [2]:

```
import math
#Variable declaration
L=50*10**-3#L=primary inductance of a transformer in henry
C=(200*10**-12)#C=capacitor connected across transformer in farad
R=50#dc resistance of primary coil in ohm
hie=2000#hie=input impedance in ohm
hre=10**(-4)#hre=reverse voltage amplification factor
hfe=98#hfe=current gain
hoe=(0.5*10**(-4))#hoe=output impedance in mho
RB=50000#RB=resistance
#Calculations
f=1/(2*math.pi*math.sqrt(L*C))#f=frequency of oscillation
g=((hie*hoe)-(hfe*hre))#g=dhe=delta he
#M=mutual inductance in henry between the transformer primary and the secondary coils for sustained oscillations
M=((RB/hfe)*((C*R)+(hoe*L)))+((C*R*hie)/hfe)+((L*g)/hfe)
#Results
print "Frequency of oscillation is = %.1f kHz"%(f/10**3)#f is converted in terms of kHz
print "Mutual inductance is = %.2f mH"%(M/10**-3)#M is converted in terms of mH
```

In [4]:

```
import math
import numpy as np
from numpy.linalg import inv
#Variable declaration
#L1 and L2=inductances in henry in a Hartley oscillator
#Suppose L1=a
#L2=b
f=60*10**3#f=frequency in Hz
C=400*10**(-12)#C=capacitance in Farad
#Calculations
#Also tuning capacitance varies from 100 pF to 400 pF
#f=1/(2*%pi*sqrt((L1+L2)*C)) where f=frequency of a Hartley oscillator which varies from 60 kHz to 120 kHz
#d=L1+L2=a+b
#d=1/(((2*%pi*f)**2)*C)
d=1/(((2*math.pi*f)**2)*C)#.......(1)
#e=L2/L1=hfe/dhe
hfe=90#hfe=current gain
dhe=0.2#dhe=delta he
e=hfe/dhe#..........(2)
#From equation (1) and (2)
#L*x=y
x=np.matrix([[1, 1], [e, -1]])
y=np.matrix([[d],[0]])
L=inv(x)*y
#Results
print "Inductance L1 is = %.f uH"%((L[0])/10**-6)#converting L(1) in terms of micro Henry
print "Inductance L2 is = %.2f mH"%((L[1])/10**-3)#converting L(2) in terms of mH
```

In [6]:

```
import math
#Variable declaration
L=20*10**-3#L=inductance in henry
C1=(200*10**(-12))#C1=capacitance in farad
C2=(300*10**(-12))#C2=capacitance in farad
#Calculations
Cs=((C1*C2)/(C1+C2))
f=1/(2*math.pi*math.sqrt(L*Cs))
#Result
print "Frequency of oscillation is = %.f kHz"%(f/10**3)#converting f in terms of kHz
```

In [8]:

```
import math
#Variable declaration
R=4700#R=resistance in a phase-shift oscillator in ohm
C=(0.01*10**(-6))#C=capacitance in a phase-shift oscillator in farad
#Calculations
f=1/(2*math.pi*math.sqrt(10)*R*C)
#Result
print "Frequency of oscillation f is = %.2f kHz"%(f/10**3)#converting f in terms of kHz
```

In [10]:

```
import math
#Variable declaration
f=30#f=frequency of oscillation of a Wien-bridge oscillator in Hz
C=(500*10**(-12))#C=capacitance in farad
#Calculations&Results
#f=1/2*math.pi*R*C#R=resistance in ohm
R=1/(2*math.pi*f*C)
print "Resistance needed to span the frequency range,R=%.1f Mohms"%(R/10**6)#converting R in terms of Mega ohms
#C1=50pF C2=500pF where C1,C2 are variable capacitances in a Wien bridge oscillator
#ratio of capacitance=(1:10)
#frequency range is 30 Hz to 300 Hz with R=10.6 Megaohms
#for the next frequency range from 300 Hz to 3 kHz ,new R=(10.6/10)=1.06 Megaohm
#for frequency range 3 kHz to 30kHz,R=1.06/10=106 Kilo-ohm
#So,three values of R are 10.6 Megaohm,1.06 Megaohm,106 Kilo ohm
A=6#A=gain of amplifier
#R2/(R1+R2)=(1/3)-(1/A)=(1/3)-(1/6)
#1+(R1/R2)=6
#Hence R1/R2=5
#R3=(R1/R2)
R3="5:1"
print "The ratio of the resistances in the other arms of the bridge,R1/R2 is =",R3
```

In [12]:

```
import math
#Variable declaration
#Q=Quality factor
L=3.5#L=inductance in henry
f=450000#f=frequency in Hz
R=9050#R=resistance in ohm
#Calculations
Q=(2*math.pi*f*L)/R
#Result
print "Quality factor is %.f"%Q
```