def fun(z):
g = np.zeros(4 * N)
for i in range(4 * N):
f = np.zeros(4 * N)
for j in range(4 * N):
f[i] = f[i] + M_kk[i][j] * z[j] * np.arcsinh(w_c / z[j])
g[i] = f[i] - z[i]
return(g)
z = fsolve(fun, dk)
When solving the equation, it reports the error: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'. How can I solve this issue?
ComplexWarning: Casting complex values to real discards the imaginary part
f[i] = f[i] + M_kk[i][j] * z[j] * np.arcsinh(w_c / z[j])
ComplexWarning: Casting complex values to real discards the imaginary part
g[i] = f[i] - z[i]
Traceback (most recent call last):
File "C:\Users\AppData\Local\Programs\Python\Python310\Lib\site-packages\simple test.py", line 112, in <module>
z = fsolve(fun, dk)
File "C:\Users\AppData\Local\Programs\Python\Python310\Lib\site-packages\scipy\optimize\_minpack_py.py", line 160, in fsolve
res = _root_hybr(func, x0, args, jac=fprime, **options)
File "C:\Users\AppData\Local\Programs\Python\Python310\Lib\site-packages\scipy\optimize\_minpack_py.py", line 237, in _root_hybr
retval = _minpack._hybrd(func, x0, args, 1, xtol, maxfev,
TypeError: Cannot cast array data from dtype('complex128') to dtype('float64') according to the rule 'safe'