newton1 - dfdx = (curfx - fpdlt)/delta ; % Find new guess...

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

View Full Document Right Arrow Icon
% fig_newton.m function root = fig_newton( func, x0, delta, epsilon, ax ) axis ; maxstep = 40 ; width = ax(2)-ax(1) ; xdata = ax(1):(ax(2)-ax(1))/200:ax(2) ; for i=1:length(xdata) ydata(i) = feval( func, xdata(i) ) ; end steps = 0 ; curx = x0 ; curfx = feval( func, curx ) ; curdlt = 2*delta ; % Estimate df/dx fpdlt = feval( func, curx+delta ) ;
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: dfdx = (curfx - fpdlt)/delta ; % Find new guess dx = curfx/dfdx ; newx = curx + dx ; newfx = feval( func, newx ) ; ep = [ curx curfx ; newx 0 ] ; curdlt = abs(curx-newx) ; plot(xdata,ydata,'-',ep(:,1),ep(:,2),'-',curx,curfx,'x',newx,newfx,'x'); grid on ; curx = newx curfx = newfx ; figure(1); pause steps = steps + 1 ; end root = curx ; axis ;...
View Full Document

Ask a homework question - tutors are online