function [x, y, err, iter] = secant(f,x0,x1,xtol,ytol,maxit) % this is the secant method function a = x0; b = x1; counter = 0; while ((abs(a-b) > xtol) || (abs(feval(f,b)) > ytol)) && (counter < maxit) counter = counter + 1; xn = b - feval(f,b)*(b-a)./(feval(f,b)-feval(f,a)); a = b; b = xn; x(counter) = b; y(counter) = feval(f,b); end iter = counter; err = abs(b-a); function Swrapper(f,a,b) % this function takes a function 'f' % and two vectors of the same size % which correspond to the initial % choices in the secant method algorithm LEN = length(a); for i = 1:LEN [x, y, err, iter] = secant(f,a(i),b(i),10^(-14),10^(-12),50); X(i) = x(end); end X