Created
November 14, 2011 09:51
-
-
Save zhhailon/1363631 to your computer and use it in GitHub Desktop.
Newton Iteration Method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Created by ZHANG Hailong <[email protected]> | |
# Newton Iteration Method | |
# f(x) = X^2 - a = 0. Here a = 2. | |
# Xn+1 = Xn - (Xn^2 - 2) / 2Xn = Xn / 2 + 1 / Xn. | |
x0 = 1.0 | |
n = 5 | |
x = x0 / 2 + 1 / x0 | |
(n - 1).times do | |
x = x / 2 + 1 / x | |
end | |
puts x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment