{{{id=26| # Copyright 2009, P. Lutus # Released under the GPL (http://www.gnu.org/copyleft/gpl.html) /// }}} {{{id=0| %auto # reset() # commented out for now -- ticket 7255 # special equation rendering def render(x,name = "temp.png",size = "normal"): # if(type(x) != type("")): x = latex(x) latex.eval("\\" + size + "$" + x + "$",{},"",name) var('r_l r_c X_l X_c f a b c x y z zl zc r l c L C omega') radians = pi/180.0 degrees = 180.0/pi # define arg(x) in degrees def argd(x): return N(arg(x) * degrees) # complex plot function def plt(q,a,b,typ = abs,col = 'blue'): return plot(lambda x: typ(q(x)),(x,a,b),rgbcolor=col) omega = 2*pi*f # series rlc circuit definition zs(r,l,c,f) = r + (i*omega*l) - i/(omega*c) # parallel rlc circuit definition # from http://hyperphysics.phy-astr.gsu.edu/Hbase/electric/rlcpar.html#c2 zp(r_l,r_c,l,c,f) = ((r_l + i*omega*l)*(r_c - i/(omega*c))) / ((r_l+r_c)+i*(omega*l-1/(omega*c))) /// }}} {{{id=60| # series rlc circuit plot # plotting range: a = start, b = end (Hertz) a = 500 b = 2500 # r = .1 ohms, l = 100 microhenries, c = 100 microfarads r = .1 l = 1e-4 c = 1e-4 q(f) = zs(r,l,c,f) p1 = plt(1/q,a,b,abs,'#800000') p2 = plt(q,a,b,arg,'#008000') show(p1+p2,figsize=(4,3),axes_labels=('freq Hz','admittance $\mho$')) /// }}} {{{id=79| N(1/(2*pi*sqrt(l*c))) /// 1591.54943091895 }}} {{{id=82| find_root(lambda f: float(arg(zs(r,l,c,f))),500,2500) /// 1591.5494309189535 }}} {{{id=61| for n in range(500,2510,100): f = float(n) z = N(zp(0.1,0.1,1e-4,1e-4,f)) print "%6.1f %.1f (%.1f,%+4.1f i) %+5.1f" % (f,z.abs(),z.real(),z.imag(),argd(z)) /// 500.0 0.4 (0.1,+0.3 i) +70.2 600.0 0.5 (0.1,+0.4 i) +72.3 700.0 0.6 (0.2,+0.5 i) +73.5 800.0 0.7 (0.2,+0.7 i) +74.0 900.0 0.8 (0.2,+0.8 i) +73.8 1000.0 1.0 (0.3,+1.0 i) +72.8 1100.0 1.3 (0.4,+1.2 i) +70.9 1200.0 1.7 (0.6,+1.5 i) +67.5 1300.0 2.2 (1.1,+2.0 i) +61.5 1400.0 3.1 (2.0,+2.4 i) +50.7 1500.0 4.3 (3.8,+2.2 i) +30.0 1600.0 5.0 (5.0,-0.3 i) -3.0 1700.0 4.2 (3.5,-2.3 i) -32.7 1800.0 3.2 (2.1,-2.4 i) -49.6 1900.0 2.5 (1.3,-2.1 i) -58.7 2000.0 2.0 (0.9,-1.8 i) -63.9 2100.0 1.7 (0.7,-1.6 i) -67.2 2200.0 1.5 (0.5,-1.4 i) -69.4 2300.0 1.3 (0.4,-1.2 i) -70.9 2400.0 1.2 (0.4,-1.1 i) -71.9 2500.0 1.1 (0.3,-1.0 i) -72.6 }}} {{{id=62| # parallel rlc circuit plot # plotting range: a = start, b = end (Hertz) a = 500 b = 2500 # r_l = .1 ohms, r_c = .1 ohms # l = 100 microhenries, c = 100 microfarads r_l = .1 r_c = .1 l = 1e-4 c = 1e-4 q(f) = zp(r_l,r_c,l,c,f) p1 = plt(q,a,b,abs,'#800000') p2 = plt(q,a,b,arg,'#008000') show(p1+p2,figsize=(4,3),axes_labels=('freq Hz','impedance $\Omega$')) /// }}} {{{id=86| # parallel rlc circuit log/linear plot # plotting range: a = start, b = end, units f*10^n a = 0 b = 7 r_l = .25 r_c = .75 l = 1e-4 c = 1e-4 q(n) = zp(r_l,r_c,l,c,10^n) p1 = plt(q,a,b,abs,'#800000') show(p1,figsize=(4,3),axes_labels=('$f = 10^n Hz$','impedance $\Omega$'),ymin=0) /// }}} {{{id=83| render("z = \\frac{(r_l+i\\omega l)(r_c - \\frac{i}{\\omega_c})}{(r_l + r_c)+i(\\omega_l-\\frac{1}{\\omega_c})}","equ_impedance_parallel.png","huge") /// }}} {{{id=68| render("X_l = \omega_L","equ_inductive_reactance.png","Large") /// }}} {{{id=72| render("$X_c = -\\frac {1}{\omega_C}$","equ_capacitive_reactance.png","Large") /// }}} {{{id=73| render("$\omega = 2 \pi f$","equ_omega.png","Large") /// }}} {{{id=74| render("$z = r + i \omega_L - \\frac {i}{\omega_C}$","equ_rlc_impedance.png","Large") /// }}} {{{id=75| show(abs(z)) ///
{\left| z \right|}
}}} {{{id=78| render("$f\_0 = \\frac {1}{2 \pi \sqrt {L C}}$","equ_rlc_resonance.png","Large") /// }}} {{{id=81| N(abs(zp(7,13,1e-4,1e-4,1e12))) /// 13.0000000000000 }}} {{{id=84| for n in range(0,7): print "f = 10^%d, z = %5.2f" % (n,N(abs(zp(.25,.75,1e-4,1e-4,10^n)))) /// f = 10^0, z = 0.25 f = 10^1, z = 0.25 f = 10^2, z = 0.26 f = 10^3, z = 0.86 f = 10^4, z = 0.78 f = 10^5, z = 0.75 f = 10^6, z = 0.75 }}} {{{id=85| render("$\mho$","mho_symbol.png","Large") /// }}} {{{id=87| render("$\Omega$","ohm_symbol.png","Large") /// }}} {{{id=88| render("$\mho = \Omega i^2$","ohm_times_i_squared.png","Large") /// }}} {{{id=89| render("$\infty$ = 8i","8_times_i.png","Large") /// }}} {{{id=91| j=i i=0 j^2 /// -1 }}} {{{id=92| x*i^2 /// -4*I - 3 }}} {{{id=93| x=a+b*i /// }}} {{{id=94| x /// a + I*b }}} {{{id=95| var('a b') /// (a, b) }}} {{{id=96| x*i^2 /// -a - I*b }}} {{{id=97| /// }}}