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
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
In [ ]: