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

조회 수: 20 (최근 30일)
Cecilio Flores Roque
Cecilio Flores Roque 2020년 10월 19일
답변: Asad (Mehrzad) Khoddam 2020년 10월 20일
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개)

Asad (Mehrzad) Khoddam
Asad (Mehrzad) Khoddam 2020년 10월 20일
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)));

카테고리

Help CenterFile Exchange에서 Animation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by