-3

I have an expression for a complex function as follows:

f(z) = 1/jwC + (R1(1+jwC1) + R2(1+jwC2))/(1+jwR1C1)(1+jwR2C2)

where j = sqrt(-1)

How do I compute f(z) in Python, given the values of w, R1, R2, C, C1, C2 and then seperate out the real and imaginary portions of f(z)?

wovano
  • 4,543
  • 5
  • 22
  • 49
Bidisha Das
  • 177
  • 2
  • 11

1 Answers1

1

Complex numbers are one of the standard types in Python.

So you could just write:

#!/usr/bin/env python3

def f(w, R1, R2, C, C1, C2):
    return 1 / (1j * w * C) + (R1 * (1 + 1j * w * C1) + R2 * (
        1 + 1j * w * C2)) / ((1 + 1j * w * R1 * C1) * (1 + 1j * w * R2 * C2))


result = f(w=1000, R1=100, R2=200, C=100.0e-9, C1=100.0e-9, C2=200.0e-9)
print(result)
print(result.real)
print(result.imag)

(NB: please check the math epxression yourself, since I didn't verify if the results are actually correct. I may have misinterpreted your equation or made a typo.)

wovano
  • 4,543
  • 5
  • 22
  • 49