clc
close all
clear all
fname = 'func';
fpname='dfunc';disp(sprintf('k fval fpval '))
delta = .0001;
a = input('Enter a value:');
b = input('Enter b value:');
x0 = linspace(-10,10,201);
y0 = feval(fname,x0,a,b);
xc = input('Enter starting value:');
fc = feval(fname,xc,a,b);
%fpc=feval(fpname,xc,a,b);
fpc = (feval(fname,xc+delta,a,b)-fc)/delta;
k=0;
while input('Newton step? (0=no, 1=yes)')
k=k+1;
x(k) = xc; y(k) = fc;
xnew = xc - fc/fpc;
xc = xnew;
fc = feval(fname,xc,a,b);
%fpc= feval(fpname,xc,a);
fpc = (feval(fname,xc+delta,a,b)-fc)/delta;
disp(sprintf('%2.0f %20.15f %20.15f %20.15f',k,xc,fc,fpc))
end
x(k) = xc
y(k) = fc
plot(x0,y0,x,y,'*')