Skip to content

Instantly share code, notes, and snippets.

@perryqh
Created February 16, 2010 20:04
Show Gist options
  • Save perryqh/305850 to your computer and use it in GitHub Desktop.
Save perryqh/305850 to your computer and use it in GitHub Desktop.
def newton_raphson(f, f_deriv, start, precision = 5)
k_plus_one = start
k = 0.0
while ((k - 1) * 10**precision).to_f.floor != ((k_plus_one - 1) * 10**precision).to_f.floor
k = k_plus_one
k_plus_one = k - f.call(k) / f_deriv.call(k)
end
k_plus_one
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment