'Error trying to perform nonlinear regression using scipy.optimize.least_squares
I have a system of 28 nonlinear equations with 27 dependent variables.
x0 = np.ones(27)
def one_VI_set_012(x):
gamma1 = x[0] + 1j*x[1]
Zw1 = x[2] + 1j*x[3]
gamma0 = x[4] + 1j*x[5]
Zw0 = x[6] + 1j*x[7]
len1 = x[8]
len2 = len - x[8]
I_left_f1 = x[9] * np.exp(1j*x[10]*np.pi/180)
I_right_f1 = x[11] * np.exp(1j * x[12]*np.pi/180)
V_f1 = x[13] * np.exp(1j * x[14]*np.pi/180)
I_left_f2 = x[15] * np.exp(1j*x[16]*np.pi/180)
I_right_f2 = x[17] * np.exp(1j * x[18]*np.pi/180)
V_f2 = x[19] * np.exp(1j * x[20]*np.pi/180)
I_left_f0 = x[21] * np.exp(1j*x[22]*np.pi/180)
I_right_f0 = x[23] * np.exp(1j * x[24]*np.pi/180)
V_f0 = x[25] * np.exp(1j * x[26]*np.pi/180)
return [ \
np.real(V_f1 - (Vbeg_1*np.cosh(gamma1*len1) - Ibeg_1*Zw1*np.sinh(gamma1*len1))),
np.real(I_left_f1 - (-Vbeg_1*np.sinh(gamma1*len1)/Zw1 + Ibeg_1*np.cosh(gamma1*len1))),
np.real(Vend_1 - (V_f1*np.cosh(gamma1*len2) - I_right_f1*Zw1*np.sinh(gamma1*len2))),
np.real(Iend_1 - (-V_f1*np.sinh(gamma1*len2)/Zw1 + I_right_f1*np.cosh(gamma1*len2))),
np.real(V_f2 - (Vbeg_2*np.cosh(gamma1*len1) - Ibeg_2*Zw1*np.sinh(gamma1*len1))),
np.real(I_left_f2 - (-Vbeg_2*np.sinh(gamma1*len1)/Zw1 + Ibeg_2*np.cosh(gamma1*len1))),
np.real(Vend_2 - (V_f2*np.cosh(gamma1*len2) - I_right_f2*Zw1*np.sinh(gamma1*len2))),
np.real(Iend_2 - (-V_f2*np.sinh(gamma1*len2)/Zw1 + I_right_f2*np.cosh(gamma1*len2))),
np.real(V_f0 - (Vbeg_0*np.cosh(gamma0*len1) - Ibeg_0*Zw0*np.sinh(gamma0*len1))),
np.real(I_left_f0 - (-Vbeg_0*np.sinh(gamma0*len1)/Zw0 + Ibeg_0*np.cosh(gamma0*len1))),
np.real(Vend_0 - (V_f0*np.cosh(gamma0*len2) - I_right_f0*Zw0*np.sinh(gamma0*len2))),
np.real(Iend_0 - (-V_f0*np.sinh(gamma0*len2)/Zw0 + I_right_f0*np.cosh(gamma0*len2))),
np.real((I_left_f1 - I_right_f1) - (I_left_f0 - I_right_f0)),
np.real((I_left_f1 - I_right_f1) - (I_left_f2 - I_right_f2)),
np.imag(V_f1 - (Vbeg_1*np.cosh(gamma1*len1) - Ibeg_1*Zw1*np.sinh(gamma1*len1))),
np.imag(I_left_f1 - (-Vbeg_1*np.sinh(gamma1*len1)/Zw1 + Ibeg_1*np.cosh(gamma1*len1))),
np.imag(Vend_1 - (V_f1*np.cosh(gamma1*len2) - I_right_f1*Zw1*np.sinh(gamma1*len2))),
np.imag(Iend_1 - (-V_f1*np.sinh(gamma1*len2)/Zw1 + I_right_f1*np.cosh(gamma1*len2))),
np.imag(V_f2 - (Vbeg_2*np.cosh(gamma1*len1) - Ibeg_2*Zw1*np.sinh(gamma1*len1))),
np.imag(I_left_f2 - (-Vbeg_2*np.sinh(gamma1*len1)/Zw1 + Ibeg_2*np.cosh(gamma1*len1))),
np.imag(Vend_2 - (V_f2*np.cosh(gamma1*len2) - I_right_f2*Zw1*np.sinh(gamma1*len2))),
np.imag(Iend_2 - (-V_f2*np.sinh(gamma1*len2)/Zw1 + I_right_f2*np.cosh(gamma1*len2))),
np.imag(V_f0 - (Vbeg_0*np.cosh(gamma0*len1) - Ibeg_0*Zw0*np.sinh(gamma0*len1))),
np.imag(I_left_f0 - (-Vbeg_0*np.sinh(gamma0*len1)/Zw0 + Ibeg_0*np.cosh(gamma0*len1))),
np.imag(Vend_0 - (V_f0*np.cosh(gamma0*len2) - I_right_f0*Zw0*np.sinh(gamma0*len2))),
np.imag(Iend_0 - (-V_f0*np.sinh(gamma0*len2)/Zw0 + I_right_f0*np.cosh(gamma0*len2))),
np.imag((I_left_f1 - I_right_f1) - (I_left_f0 - I_right_f0)),
np.imag((I_left_f1 - I_right_f1) - (I_left_f2 - I_right_f2))]
root = least_squares(one_VI_set_012,x0)
Vbeg_1, Ibeg_1 etc. here are the complex numbers which are given in the rest of the code. I've tried to perform regression on a simple system of 3 equations and all was good, but in real abovemetioned task I receive an error:
Exception has occurred: TypeError
ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Thank you very much in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
