This script defines a number of functions to calculate the impedance of resistor - capacitor combinations
- zcap(c,f) impedance of capacitance c at frequency f, returns a complex number for impedance
- zseries(r,c,f) impedance of series resistance r and capacitance c at frequency f, returns a complex number for impedance
- zparall(r,c,f) impedance of parallel resistance r and capacitance c at frequency f, returns a complex number for impedance
- z_all() to keep things interactive, this function asks for input values and returns impedance of bith series and parallel combinations
Exponential notation can be used to input values for example
1e-6
for a capacitance value means
0.000001 Farad or
1 micro Farad
The code also runs on CPython on a PC
from math import * from cmath import phase def out(x,s): print("{0}={1:.8}{2:+.8}j".format(s,x.real,x.imag)) print("|{0}|={1:.10} Ohm".format(s,abs(x))) print("phase={0:.6} deg".format(degrees(phase(x)))) def zcap(c,f): zc=1/(2*pi*f*1j*c) return zc def zseries(r,c,f): zc=zcap(c,f) zser=r+zc return zser def zparall(r,c,f): zc=zcap(c,f) zp=1/(1/r+1/zc) return zp def z_all(): print("Impedance combinations of\nresistor - capacitor") r=float(input("r [Ohm]? ")) c=float(input("c [Farad]? ")) f=float(input("f [Hz]? ")) zc=zcap(c,f) zs=zseries(r,c,f) out(zs,"zser") zp=zparall(r,c,f) out(zp,"zpar") z_all()