Newton Raphson - Multiple functions
Version 1.0.0 (2.23 KB) by
Victor Brasil
Newton-Raphson iterative method to find roots of a function (or multiple functions). Adjustable residue tolerance, max number of iterations
% Newton-Raphson iterative method to find roots of a function.
% Ex.: roots = NewtonRaphson(f, x, [tol], [MaxIt], [Delta])
%
% There are 2 mandatory inputs (f and x) and 3 optional arguments (tol,
% MaxIt, and Delta).
%
% The function returns 1 output (x).
%
% INPUTS:
% 1. f - function handle to which the roots should be found. It should
% be noted that if f is a multivariable function handle (for example, f =
% @(x, y) [x^2 + y^2 - 3^2; x - y = 3]), then the function handle
% should be rewritten as a one vector variable function handle (for
% example, f = @(x) [x(1)^2 + x(2)^2 - 3^2; x(1) - x(2) = 3]).
% Additionally, the output size of the function handle should always
% match the variable x size.
% 2. x - initial guess for the roots of the vector variable.
% 3. [Optional] tol - convergence tolerance.
% Type: Double. Default: 1e-3.
% 4. [Optional] MaxIt - Maximum number of iterations.
% Type: Double. Default: 1e3.
% 5. [Optional] Delta - Step for numerical derivative.
% Type: Double. Default: 1e-6.
%
% OUTPUTS:
% 1. roots - roots of the function. If the algorithm does not converge, then x
% is NaN. x is the same size and type as the input x.
%
% Examples:
% roots = NewtonRaphson(@(x) [x(1) - x(2) - 2; x(2) - 5], [0; 0])
% roots = NewtonRaphson(@(x) [x(1) - x(2) - 2; x(2) - 5], [0; 0]), 1e-6, 50, 1e-12)
%
% © Universidade de Brasilia, 2023
% Power Quality Laboratory (LQEE)
% Author: Victor do Prado Brasil
% Version History:
% 2023/07/13 - Creation of the function.
Cite As
Victor Brasil (2026). Newton Raphson - Multiple functions (https://www.mathworks.com/matlabcentral/fileexchange/134666-newton-raphson-multiple-functions), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2023a
Compatible with any release
Platform Compatibility
Windows macOS LinuxTags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0 |
