Skip to content

Instantly share code, notes, and snippets.

@agustingianni
Created November 16, 2009 15:15
Show Gist options
  • Save agustingianni/236051 to your computer and use it in GitHub Desktop.
Save agustingianni/236051 to your computer and use it in GitHub Desktop.
-- Derivada numerica en x0 con paso h
-- http://en.wikipedia.org/wiki/Numerical_differentiation
derivada :: (Double -> Double) -> Double -> Double -> Double
derivada f x0 h = (f (x0 + h) - f x0) / (2*h)
newton :: (Double -> Double) -> Double -> Double
newton f x0 = do
let x1 = x0 - (f x0 / (derivada f x0 0.01))
if abs (x1 - x0) < 0.001 then x1 else newton f x1
function :: Double -> Double
function x = x^2-4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment