Newton's Method to find root of a system of equations

62 views (last 30 days)
Hello, I this is my Newton's Method, but I do not know what changes to make to be able to find the root of a system of equations f(x) = 0.
My inputs must be able to accept funtion handles for f, an the Jacobian K, initial vector x0 and my output should be the approximate root xn.
What do I have to do to make my newtons method be able to to find the root of a system of equations?
% Newton's Method
% Inputs:
% f = the function f (we're trying to solve f(x) = 0)
% fprime = derivative of f
% x0 = initial guess
% tol = maximum error tolerance on the residual
function xn = newtonsMethod(f, fprime, x0, tol)
maxiter = 50; % Max number of iterations
rn = abs(f(x0)); % Initialize residual
xn = x0; % Initialize iterate
n = 0; % Iteration number
while rn > tol && n < maxiter
n = n+1;
xn = xn - f(xn) ./ fprime(xn);
rn = abs(f(xn));
if n == maxiter
warning('Maximum number of iterations reached');

Answers (1)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam on 20 Oct 2020
For solving a system of equations, you should solve a system of equation insetead of division:
% single equation
xn = xn - f(xn) ./ fprime(xn);
% system of equations:
xn = xn - fprime(xn)\f(xn);
rn = sum(abs(f(xn)));


Find more on Numerical Integration and Differential Equations in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!