rc.py

Created by vnap0v

Created on June 28, 2025

668 Bytes

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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.