The Newton-Raphson method (named after Isaac Newton 1669 and Joseph Raphson 1690) is a method for generating a numerical sulution for systems of equations.
Example for f(x) = -1/4x^4+5/2x^3-7x^2+8x-1, x0 = 2 and eps = 0.1 generated with MatLab:
MatLab implementation for :
function y = newton_raphson_method(f,x,x0,eps)
fx = jacobian(f,x);
v = num2cell(x0);
b = f(v{:});
while norm(b) > eps
d = fx(v{:})\f(v{:});
x0 = x0 - d;
v = num2cell(x0);
b = f(v{:});
end
y = x0;
end
Note that the MatLab implementation doesn’t exit when the function has no root.
Download: newton_raphson_method.m
See newton_raphson_method_usage.m for how to use the implementation. You need the Symbolics library.