23.3.3 Finding approximate solutions to systems of equations
In Section 23.3.2
it was shown how to use the
fsolve and
cfsolve commands
to solve equations. This section will discuss systems of equations.
As before, the cfsolve
command is the complex version of
fsolve, with the same arguments. The only difference is that
cfsolve gives numeric solutions over the complex numbers,
even if Xcas is not in complex mode (see
Section 2.5.5). fsolve will return complex roots,
but only in complex mode.
-
For solving systems of equations,
fsolve takes three mandatory arguments and one
optional argument:
-
eqns, a list of equations (or expressions,
considered to be equal to zero) to solve.
- vars, a list of the variables.
- Optionally, init, a list initial values for the variables.
- Optionally, method, the method to use. The possible methods are:
dnewton_solver,
hybrid_solver,
hybrids_solver,
newtonj_solver,
hybridj_solver, and
hybridsj_solver.
- fsolve(eqns,vars ⟨,init,method ⟩)
returns an approximate solution to eqns.
- The methods are inherited from the GSL. The methods whose names end
with j_solver use the jacobian matrix, the rest use
approximations for the derivatives.
All methods use an iteration of Newton kind
The four hybrid methods also apply the method of gradient descent when
the Newton iteration would make a too large of a
step. The length of the step is computed without scaling
for hybrid_solver and hybridj_solver
or with scaling (computed from f′(xn)) for
hybrids_solver and hybridsj_solver.
Examples
Input in real mode:
fsolve([x^2+y+1,x+y^2-1],[x,y]) |
|
| ⎡
⎢
⎣ | 0.0 | −1.0 |
−0.453397651516 | −1.2055694304 |
| ⎤
⎥
⎦ |
|
| | | | | | | | | | |
|
Input in complex mode:
fsolve([x^2+y+1,x+y^2-1],[x,y]) |
|
| ⎡
⎢
⎢
⎢
⎣ | 0.0 | −1.0 |
0.226698825758−1.46771150871 i | 1.1027847152+0.665456951153 i |
0.226698825758+1.46771150871 i | 1.1027847152−0.665456951153 i |
−0.453397651516 | −1.2055694304 |
| ⎤
⎥
⎥
⎥
⎦ |
|
| | | | | | | | | | |
|
Input in any mode:
cfsolve([x^2+y+1,x+y^2-1],[x,y]) |
|
| ⎡
⎢
⎢
⎢
⎣ | 0.0 | −1.0 |
0.226698825758−1.46771150871 i | 1.1027847152+0.665456951153 i |
0.226698825758+1.46771150871 i | 1.1027847152−0.665456951153 i |
−0.453397651516 | −1.2055694304 |
| ⎤
⎥
⎥
⎥
⎦ |
|
| | | | | | | | | | |
|
cfsolve([x^2+y+2,x+y^2+2],[x,y]) |
|
| ⎡
⎢
⎢
⎢
⎣ | 0.5+1.65831239518 i | 0.5−1.65831239518 i |
0.5−1.65831239518 i | 0.5+1.65831239518 i |
−0.5+1.32287565553 i | −0.5+1.32287565553 i |
−0.5−1.32287565553 i | −0.5−1.32287565553 i |
| ⎤
⎥
⎥
⎥
⎦ |
|
| | | | | | | | | | |
|
Example
fsolve([x^2+y-2,x+y^2-2],[x,y],[2,2],dnewton_solver) |