Created
April 19, 2012 06:09
-
-
Save zaman/2419031 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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