Newton - i if display fprintf (' step xr yr Ea\n'); end e...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
function [xr] = Newton (f, fp, x0, Edes, display) % NEWTON Finds a root by performing a Newton-Raphson search. % Inputs: f = a function of one variable % fp = derivative of function % x0 = initial guess at root % Edes = tolerance in x % (function stops when change in x <= Edes) % display = display option (0 = no output, 1 = output, defaults to 0) % Outputs: xr = estimate of root % if nargin < 5; display = 0; end
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: i if display fprintf (' step xr yr Ea\n'); end e xold = x0; x for k = 1:100 % 100 max iterations xr = xold - f(xold)/fp(xold); yr = f(xr); Ea = abs(xr - xold); if display fprintf ('%5d %12.6f %12.6f %12.6f\n', k, xr, yr, Ea); end if Ea &lt;= Edes || yr == 0 % error acceptably small or direct hit return; end xold = xr; end e error ('Newton-Raphson search has not converged'); e end...
View Full Document

This note was uploaded on 10/18/2010 for the course SYSC 3600 taught by Professor Adsd during the Spring '10 term at Universidad Alfonso X El Sabio.

Ask a homework question - tutors are online