C Vith
C Vith

Reputation: 111

How to calculate complex simultaneous equations in python?

I need to obtain three complex numbers from a set of three equations which is part of an error correction procedure for a set of S-parameters.

import numpy as np

G_A1 = -1 + 0j
G_A2 = 0 + 0j
G_A3 = 1 + 0j
G_M1 = -0.5323 - 0.0163j
G_M2 = -11.1951 - 37.7373j
G_M3 = 0.5528 + 0.1621j

a = np.array([[G_A1,G_A2,G_A3], [1,1,1], [(-G_A1*G_M1),(-G_A2*G_M2),(-G_A3,G_M3)]])
b = np.array([G_M1,G_M2,G_M3])
x = np.linalg.solve(a, b)
print(x)

This gives me the error

a = np.array([[G_A1,G_A2,G_A3], [1,1,1], [(-G_A1*G_M1),(-G_A2*G_M2),(-G_A3,G_M3)]])
TypeError: a float is required

I thought I might as well try to convert the complex values to float but then I get this error.

G_M1 = float(-0.5323 - 0.0163j)
TypeError: can't convert complex to float

If complex values cannot be converted to float, what alternative method should I be using here?

Upvotes: 0

Views: 355

Answers (1)

percusse
percusse

Reputation: 3106

You have a typo in the last entry of last row which makes it a tuple

(-G_A3,G_M3)

and leads to a TypeError as an element. If you correct that the problem goes away. You also don't need to put parentheses around the expressions in this case anyways.

Upvotes: 2

Related Questions