Skip to content

Instantly share code, notes, and snippets.

@dmadisetti
Created September 15, 2014 18:49
Show Gist options
  • Save dmadisetti/8b4cc9a6520d4d415e75 to your computer and use it in GitHub Desktop.
Save dmadisetti/8b4cc9a6520d4d415e75 to your computer and use it in GitHub Desktop.
newtonRaphson
% Third stab at matlab
function out = newtonRaphson(funct,old)
delta = 0.001;
y = funct(old);
m = (funct(old+delta)-y)/delta;
new = (m*old-y)/m;
apprx = funct(new);
% Let's check to see if it hit the needed level
if abs((apprx - y)/2) < 0.01 || funct(apprx) == 0,
out = new;
return;
end
out = newtonRaphson(funct,new);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment