如何在Python中进行非线性复杂的根查找 [英] How to do nonlinear complex root finding in Python
问题描述
我想对以下非线性方程式进行根搜索,我在Python中进行了搜索,但没有用.我的代码在下面
from pylab import *
import scipy
import scipy.optimize
def z1(x,y):
temp=1+1j+x+2*y;
return temp
def z2(x,y):
temp=-1j-2*x+sqrt(3)*y;
return temp
def func(x):
temp=[z1(x[0],x[1])-1.0/(1-1.0/(z2(x[0],x[1]))),1-2.0/(z2(x[0],x[1])-4.0/z1(x[0],x[1]))]
return temp
result=scipy.optimize.fsolve(func,[1+1j,1+1j])
print result
当我运行它时,它显示错误:
---> 30 result = scipy.optimize.fsolve(func,[1 + 1j,1 + 1j])
fsolve中的C:\ Python27 \ lib \ site-packages \ scipy \ optimize \ minpack.py(func,x0,args,fprime,full_output,col_deriv,xtol,maxfev,band,epsfcn,factor,diag)
123 maxfev = 200*(n + 1)
124 retval = _minpack._hybrd(func, x0, args, full_output, xtol,
-> 125 maxfev,ml,mu,epsfcn,因子,diag)
126 else:
127 _check_func('fsolve', 'fprime', Dfun, x0, args, n, (n,n))
fsolve
从R ^ n-> R中找到函数的零.类似的函数 解决方案
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.
这篇关于如何在Python中进行非线性复杂的根查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!