I'm trying to solve a problem with 8 unknowns and 8 complex equations. I've tried to use fsolve
but I get the error message:
error: Result from function call is not a proper array of floats.
From what I've now read fsolve
doesn't support complex equations and hence my questions, how would I solve systems of complex non-linear equations in Python?
PS: I've seen the suggestion to split my problem up into imaginary and real part and use fsolve
on those separately but that is too cumbersome.
This is the relevant snippet of my code:
A=1
def equations(p):
B,C,D,F,G,H,I,J = p
return (
A+B-C-D,
1j*k0*(A-B) -1j*k1*(C-D),
B*exp(1j*k1*a1) + D*exp(-1j*k1*a1) - F*exp(1j*k0*a1) - G*exp(-1j*k0*a1),
1j*k1* ( C*exp(1j*k1*a1) - D*exp(-1j*k1*a1) ) - 1j*k0*( F*exp(1j*k0*a1) - G*exp(-1j*k0*a1) ),
F*exp(1j*k0*a1L) + G*exp(-1j*k0*a1L) - H*exp(-k2*a1L) - I*exp(k2*a1L),
1j*k0*( F*exp(1j*k0*a1L) - G*exp(-1j*k0*a1L) )- k2*( -H*exp(-k2*a1L) + I*exp(k2*a1L) ),
H*exp(-k2*a12L) + I*exp(k2*a12L) - J*exp(1j*k0*a12L),
k2*( -H*exp(-k2*a12L) + I*exp(k2*a12L) ) - 1j*k0*J*exp(1j*k0*a12L)
)
B, C, D, F, G, H, I, J = fsolve(equations, (-1,-1,-1,-1,-1,-1,-1,-1))