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

조회 수: 19(최근 30일)
Cecilio Flores Roque 2020년 10월 19일
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));
end
if n == maxiter
warning('Maximum number of iterations reached');
end
end

댓글을 달려면 로그인하십시오.

답변(1개)

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)));

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!