 # Newton Method on matrix nonlinear systems

0

## Introduction

In a previous article of the algorithmic chef (a.k.a me !), I presented Newton’s method. In this one, I’ll demonstrate it’s applicability on nonlinear systems, via matrix nonlinear systems.

## System of non-linear equations

Newton’s method could also be applied to system of nonlinear equations. Now, consider

(1) Alternatively, and in a more compact form, we can say

(2) where

(3) (4) and is an all-zero vector.

## Newton’s method in Action

Newton method in this case would iterate as follows

(5) where

(6) ## Working a step-by-step Example

To avoid confusion of notation, and align the problem with the statements above we note

(7) We have the following system (equation (1) for )

(8) Let’s compute the gradient matrix , which in this case is (9) The above derivatives are easily computed as follows

(10) Plugging (10) in (9) we get

(11) Therefore, the Newton iterations are done as follows (substitute (11) in (5) and use instead of )

(12) where the initial guess is (this is given in the requirements)

(13) It is now easy to iterate, let’s compute the values at first iteration for example

(14) Using (13), we have

(15) and so on.. Using Newton iteration, refer to the figure below

Furthermore, we see in the above, which is obtained by running the MATLAB code, which is presented in the next section, the convergence of all methods. Also, note here that subroutine is attained by using MATLAB’s fsolve function to compare it with the Newton method

## MATLAB step-by-step explanations

Now, it’s time to implement the matrix form of Newton method, enabling us to solve non-linear. Firstly, let’s define the system we have in equation (8) in a separate MATLAB function calling it root3d.m

function F = root2d(x,y,z)

F(1) = 16*x(1)^4 + 16*x(2)^4+ x(3)^4 - 16;
F(2) = x(1)^2 + x(2)^2 + x(3)^2 - 3;
F(3) = x(1)^3 - x(2);

Following the above, we will be using the above function in our main function to get the exact roots of the system (referred to as subroutine) and comparing Now, in the main function, we can easily implement our Newton method as such

Niter = 1e1;
% values of x,y,z at initial guess
v(:,1) = [1;1;1];
%functions
f =@(x1,x2,x3)[16*x1^4 + 16*x2^4+ x3^4 - 16;x1^2 + x2^2 + x3^2 - 3;x1^3 - x2];

% Newton iterations
for n = 2:Niter
x = v(1,n-1);
y = v(2,n-1);
z = v(3,n-1);

D = [64*x^3  64*y^3   4*z^3;...
2*x  2*y  2*z;...
3*x^2  -1  0];
v(:,n) = v(:,n-1) - inv(D)*f(x,y,z);
end

In order to compare our iterative approach, we shall compare it to the solution given to us by MATLAB’s fsolve function as

%Matlab subroutine
fun = @root3d;
x0 = [1,1,1];
x_subroutine = fsolve(fun,x0);

where in the above we initialized fsolve to all-ones. Next, we plot

figure
plot(v(1,:),'r','Linewidth',1)
hold on
plot(v(2,:),'m','Linewidth',1)
plot(v(3,:),'k','Linewidth',1)
plot(x_subroutine(1)*ones(Niter,1),'--*r','Linewidth',2)
plot(x_subroutine(2)*ones(Niter,1),'--*m','Linewidth',2)
plot(x_subroutine(3)*ones(Niter,1),'--*k','Linewidth',2)
xlabel('Iteration number ','Interpreter','latex')
ylabel('x','Interpreter','latex')
legend(' ',' ',' ',' subroutine',' subroutine',' subroutine','Interpreter','latex')
grid on
grid minor

Finally, our full main function looks like this


Niter = 1e1;
% values of x,y,z at initial guess
v(:,1) = [1;1;1];
%functions
f =@(x1,x2,x3)[16*x1^4 + 16*x2^4+ x3^4 - 16;x1^2 + x2^2 + x3^2 - 3;x1^3 - x2];

% Newton iterations
for n = 2:Niter
x = v(1,n-1);
y = v(2,n-1);
z = v(3,n-1);

D = [64*x^3  64*y^3   4*z^3;...
2*x  2*y  2*z;...
3*x^2  -1  0];
v(:,n) = v(:,n-1) - inv(D)*f(x,y,z);
end
%Matlab subroutine
fun = @root3d;
x0 = [1,1,1];
x_subroutine = fsolve(fun,x0);
figure
plot(v(1,:),'r','Linewidth',1)
hold on
plot(v(2,:),'m','Linewidth',1)
plot(v(3,:),'k','Linewidth',1)
plot(x_subroutine(1)*ones(Niter,1),'--*r','Linewidth',2)
plot(x_subroutine(2)*ones(Niter,1),'--*m','Linewidth',2)
plot(x_subroutine(3)*ones(Niter,1),'--*k','Linewidth',2)
xlabel('Iteration number ','Interpreter','latex')
ylabel('x','Interpreter','latex')
legend(' ',' ',' ',' subroutine',' subroutine',' subroutine','Interpreter','latex')
grid on
grid minor

The above plots the iterations given by the Newton method for the given non-linear system in matrix form, so as to get the figure below