In [1]:
from sympy import Symbol,nsolve,init_printing,Eq
from IPython.display import display
init_printing(use_latex='mathjax')
import sympy
import mpmath
mpmath.mp.dps = 15

In [2]:
Vout = Symbol('V_out')
Vin  = Symbol('V_in')
i    = Symbol('i')
R1   = Symbol('R_1')
R2   = Symbol('R_2')

e1 = Eq(i, Vin/(R1+R2))
e2 = Eq(Vout,i*R2)
display(e1,e2)

Vin  = 10
R1   = 2000
Vout = 7.5

e1 = Eq(i, Vin/(R1+R2))
e2 = Eq(Vout,i*R2)
display(e1,e2)

_a1, _a2 = nsolve((e1,e2),(R2,i),(10000,0.01))

print
print "R2 =",_a1
print "i  =",_a2


$$i = \frac{V_{in}}{R_{1} + R_{2}}$$
$$V_{out} = R_{2} i$$
$$i = \frac{10}{R_{2} + 2000}$$
$$7.5 = R_{2} i$$
R2 = 6000.0
i  = 0.00125


Triode Modeling

see Triode Modeling Notebook on the ValveStudio github page

The Child-Langmuir equation for the next sympy exampe

$$I_a = K (V_{gk} + D_aV_{ak})^{3/2}$$


In [3]:
K     = Symbol("K")
Da    = Symbol("D_a")
n     = 3.0/2.0

Vbatt = Symbol("V_batt")
Pdiss = Symbol("P_diss")
Va    = Symbol("V_a")
Vk    = Symbol("V_k")
Vg    = Symbol("V_g")

Ia    = Symbol("I_a")
Vgk   = Symbol("V_gk")
Vak   = Symbol("V_ak")

Rk    = Symbol("R_k")
Rload = Symbol("R_load")

Vbatt = 250
Va    = Vbatt/2

K     = 0.00126098
Da    = 0.01179251
Pdiss = 0.25

e1 = Eq(Va, Vbatt-Rload*Ia)
e2 = Eq(Ia, K*(Vgk + Da*Vak)**n)
e3 = Eq(Vk, Ia * Rk)
e4 = Eq(Vgk, -Vk)
e5 = Eq(Vak,Va - Vk)
e6 = Eq(Pdiss,Ia*Vak)
display(e1,e2,e3,e4,e5,e6)

ans = nsolve((e1,e2,e3,e4,e5,e6),(Rload,Rk,Ia,Vak,Vk,Vgk),(100000,100.0,0.001,100.0,1.0,-1.0))
print ans


$$125 = - I_{a} R_{load} + 250$$
$$I_{a} = 0.00126098 \left(0.01179251 V_{ak} + V_{gk}\right)^{1.5}$$
$$V_{k} = I_{a} R_{k}$$
$$V_{gk} = - V_{k}$$
$$V_{ak} = - V_{k} + 125$$
$$0.25 = I_{a} V_{ak}$$
[   62444.0481110815]
[   55.9017990964864]
[0.00200179206475592]
[   124.888096222163]
[  0.111903777836926]
[ -0.111903777836926]

In [ ]: