I'd like to solve numerically a system of quadratic equations:
$A_{11}x_1+A_{12}x_2+A_{13}x_3+B_{12}x_1x_2+B_{13}x_1x_3=C_1$ $A_{21}x_1+A_{22}x_2+A_{23}x_3+B_{21}x_2x_1+B_{23}x_2x_3=C_2$ $A_{31}x_1+A_{32}x_2+A_{33}x_3+B_{31}x_3x_1+B_{32}x_3x_2=C_3$
where $A_{ij}$, $B_{ij}$, $C_i$ are real numbers and $x_i$ the variables (here only three but I have in mind to solve systems up to 50 variables).
I've tried Newton-Krylov method (implemented in scipy) but it does not seem to be stable. I'm now trying to use routines implemented in sympy but I face a problem illustrated by this example:
from sympy import *
from sympy.abc import x,y,z
Equations = [x**2 + y + z - 1,
x + y**2 + z - 1,
x + y + z**2 - 1]
If we use solve_poly system
we obtain
solve_poly_system(Equations, x, y, z)
[(0, 0, 1), (0, 1, 0), (1, 0, 0), (-1 + sqrt(2), -1 + sqrt(2), -1 + sqrt(2)), (-sqrt(2) - 1, -sqrt(2) - 1, -sqrt(2) - 1)]
and, if we use solve_triangulated
we obtain
solve_triangulated(Equations, x, y, z)
[(0, 0, 1), (0, 1, 0), (1, 0, 0)]
Some solutions are not found by solve_triangulated
.
What is the reason? What kind of solutions can we find with solve_triangulated
?
solve_poly_system
andsolve_triangulated
you should ask in a SymPy channel like the gitter chat room or the mailing list. $\endgroup$fsolve
. You can check the gist here: gist.github.com/nicoguaro/3c964ae8d8f11822b6c22768dc9b3716 $\endgroup$fsolve
is much more stable thannewton_krylov
(which often cannot find a solution and raise an error even for small systems). Could be due to the fact that I don't know how to parametrizenewton_krylov
. I will continue withfsolve
, it can deal apparently with (quadratic) non linear systems with 100 variables in a few minutes. $\endgroup$scipy.optimize.root
withmethod=lm
and explicit jacobian in input is the best solver for my specific problem (quadratic non linear systems with a few dozens of equations). $\endgroup$