Created
August 26, 2014 22:51
-
-
Save prcastro/35a972e06a1bb7e5ae12 to your computer and use it in GitHub Desktop.
Newton 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
function newton(f::Function, df::Function, x::Real, precision::Float64 = 10.0^(-6)/5.00) | |
x_prox = x - f(x)/df(x) | |
i = 1 | |
while abs(x_prox - x) >= precision | |
x = x_prox | |
x_prox = x - f(x)/df(x) | |
i += 1 | |
end | |
println("Numero de iterações: ", i) | |
return x_prox | |
end | |
d(x) = 4/3 * e^(2 - 0.5x) * (1 + x^(-1)*log(x)) | |
_d(x) = 4/3 * (0.5*e^(2 - 0.5x) * (1 + x^(-1)*log(x)) + e^(2 - 0.5x) * (1 - log(x)/x^2)) | |
dn = newton(d,_d,9.0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment