How to do nonlinear complex root finding in Python

后端 未结 2 746
时光取名叫无心
时光取名叫无心 2021-01-12 09:18

I want to do a root search for the following nonlinear equations, I do it in Python but it doesn\'t work. my code is below

from pylab import *
import scipy
i         


        
2条回答
  •  花落未央
    2021-01-12 09:45

    fsolve finds zeros of functions from R^n -> R. The similar function root finds zeros of functions from R^n -> R^m.

    It looks like you're trying to find zeros of a function from C^2 -> C^2, which as far as I know scipy.optimize doesn't support directly - but you could try writing it a function from R^4 -> R^4 and then using root. For example, something along the lines of:

    def func_as_reals(x):
        r1, c1, r2, c2 = x
        a, b = func([complex(r1, c1), complex(r2, c2)])
        return [a.real, a.imag, b.real, b.imag]
    

    should work, though it might be significantly faster to do it directly on the real numbers instead of repeatedly wrapping into complex and unwrapping.

提交回复
热议问题