Newton-Raphson method (multiple variables)
We want to solve a set of (non-linear) simultaneous equations in the form of
By expanding each of the above by the Taylor series, one obtains
|
f1(x) ∼ f1 (xo) + |
∂f1
∂x1
|
| ⎢ ⎢
|
x0
|
(x1 − x10) + |
∂f1
∂x2
|
| ⎢ ⎢
|
x0
|
(x2 − x20) + …+ |
∂f1
∂xn
|
| ⎢ ⎢
|
x0
|
(xn − xn0), |
| |
|
f2(x) ∼ f2 (xo) + |
∂f2
∂x1
|
| ⎢ ⎢
|
x0
|
(x1 − x10) + |
∂f2
∂x2
|
| ⎢ ⎢
|
x0
|
(x2 − x20) + …+ |
∂f2
∂xn
|
| ⎢ ⎢
|
x0
|
(xn − xn0), |
| |
| | |
| fn(x) ∼ fn (xo) + |
∂fn
∂x1
|
| ⎢ ⎢
|
x0
|
(x1 − x10) + |
∂fn
∂x2
|
| ⎢ ⎢
|
x0
|
(x2 − x20) + …+ |
∂fn
∂xn
|
| ⎢ ⎢
|
x0
|
(xn − xn0). |
| |
|
If x satisfies
f1(x) = 0, f2(x) = 0, …fn(x) = 0, |
|
the above equations can be written as
| ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
= | ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
+ | ⎛ ⎜ ⎜ ⎜ ⎜ ⎜
⎜ ⎜ ⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟ ⎟ ⎟
⎟ ⎟ ⎟ ⎟ ⎠
|
| ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
, |
| (15) |
or
where J is the Jacobian matrix defined as
| |
|
| ⎛ ⎜ ⎜ ⎜ ⎜ ⎜
⎜ ⎜ ⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟ ⎟ ⎟
⎟ ⎟ ⎟ ⎟ ⎠
|
|
| |
| |
|
|
∂(f1, f2, …, fn)
∂(x1, x2, …, xn)
|
. |
| | (17) |
|
Equation (16) can be solved for x as
where J−1 is the inverse matrix of J.
Example:
Solve numerically for
(Solution)
Let
f1 ≡ x3 + y2 − 1, f2 ≡ x y − |
1
2
|
. |
|
It follows
J = |
∂(f1, f2)
∂(x, y)
|
= | ⎛ ⎜
⎜ ⎝
|
| ⎞ ⎟
⎟ ⎠
|
, |
|
and
J−1 = | ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
, |
|
so
J−1 f = | ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
| ⎛ ⎜
⎜ ⎝
|
| ⎞ ⎟
⎟ ⎠
|
= | ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
|
|
4 x3 y−3 x2−2 y3+2 y
6 x3−4 y2
|
|
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
. |
| (20) |
Hence the iteration scheme is
| ⎛ ⎜
⎜ ⎝
|
| ⎞ ⎟
⎟ ⎠
|
= | ⎛ ⎜
⎜ ⎝
|
| ⎞ ⎟
⎟ ⎠
|
− | ⎛ ⎜ ⎜ ⎜
⎜ ⎜ ⎝
|
|
xn4−xn (yn2+1)+yn
3 xn3−2 yn2
|
|
|
|
4 xn3 yn−3 xn2−2 yn3+2 yn
6 xn3−4 yn2
|
|
|
| ⎞ ⎟ ⎟ ⎟
⎟ ⎟ ⎠
|
. |
| (21) |
Sample C code:
#include <stdio.h>
#include <math.h>
int main()
{
double x=1.0, y=1.0;
int i;
for (i=0;i<=10;i++)
{ x = x -(pow(x,4) + y - x*(1 + y*y))/(3*pow(x,3) - 2*y*y);
y = y -(-3*x*x + 2*y + 4*pow(x,3)*y - 2*pow(y,3))/(6*pow(x,3) - 4*y*y);
}
printf("%f %f\n", x, y);
return 0;
}
Sample Matlab/Octave code:
x=1; y=1;
for i=0:10
eqs=[ x*x*x+y*y-1; x*y - 1/2];
jacob=[3*x*x 2*y; y x];
right=inv(jacob)*eqs;
x=x-right(1);
y=y-right(2);
end;
fprintf('%f %f\n', x, y);
Sample Mathematica code:
FindRoot[{x^3 + y^2 == 1, x y == 1/2}, {{x, 1}, {y, 1}}]
Online C compiler
Online Matlab/Octave
Wolfram Alpha
Starting (x, y) = (1.0, 1.0), the convergence was reached at
(x, y) = (0.877275, 0.569947) after only 4 iterations.
Note that this is just one of multiple roots.
It is necessary to try different initial guess to obtain other roots.