% script zeroin
% uses matlab builtin rootfinder "FZERO"
% to find a zero of a function 'fname'
close all; clear all; format long
%fname = 'func'; % user defined function-can also give as @func
%fpname='dfunc'; % user defined derivative-not required by FZERO
%disp(sprintf('k       fval       fpval   '))
delta = .0001; % function value limiting tolerance
 a = input('Enter a value:'); % parameter values for 'func'
 b = input('Enter b value:');
x0 = linspace(-10,10,201); y0 = feval(@func,x0,a,b);
xc = input('Enter starting value:');
%root = fzero(@func,xc,.0001,1,a,b); % grandfathered format
OPTIONS = optimset('MaxIter',100,'TolFun',delta,'TolX',delta^2);
root = fzero(@func,xc,OPTIONS,a,b)
y = feval(@func,root,a,b)
plot(x0,y0,root,y,'r*')

