Skip to content

Instantly share code, notes, and snippets.

@prcastro
Created August 26, 2014 22: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 prcastro/35a972e06a1bb7e5ae12 to your computer and use it in GitHub Desktop.
Save prcastro/35a972e06a1bb7e5ae12 to your computer and use it in GitHub Desktop.
Newton Method
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