Skip to content

Instantly share code, notes, and snippets.

@jdelacruz26
Created February 19, 2018 01:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdelacruz26/741bdd556ed90d05f21e960f16d796d6 to your computer and use it in GitHub Desktop.
Save jdelacruz26/741bdd556ed90d05f21e960f16d796d6 to your computer and use it in GitHub Desktop.
%///////////////////////////////////////////////////
%// Función Secante ///
%// Desarrollada por Jorge De La Cruz ///
%/ ///
%//////////////////////////////////////////////////
function xr=secante(fun,x0,x1,tol,imax)
x=[x0 x1];
f=eval(fun);
err=tol+1;
n=1;
while (err<tol)&&(n<imax)
xr=x(1,2)-f(1,2)*(x(1,1)-x(1,2))/(f(1,1)-f(1,2));
err=abs((xr-x(1,2))/xr);
error=err*100;
x(1,1)=x(1,2);
x(1,2)=xr;
f=eval(fun);
fprintf('Iteración: %d, Error: %f, Raiz: %f\n',n,error,xr)
n=n+1;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment