Skip to content

Instantly share code, notes, and snippets.

@zaman
Created April 19, 2012 06:09
Show Gist options
  • Save zaman/2419031 to your computer and use it in GitHub Desktop.
Save zaman/2419031 to your computer and use it in GitHub Desktop.
function [x,it,err] = newton1(x0,tol,fname,fpname)
% Newton's metod
% alt a) |f(x^k)| <= tol
it = 0;
x = x0;
fx = feval(fname , x);
fpx = feval(fpname, x);
err = abs(fx);
str = ' iter x-value error';
disp(str)
disp( [it,x,err] )
while err > tol
it = it+1;
xnew = x - fx/fpx;
x = xnew;
fx = feval(fname , x);
fpx = feval(fpname, x);
err = abs(fx);
disp( [it,x,err] )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment