I need to write a Haskell function that resolves the Newton-Raphson algorithm by passing a function, its derivative and the initial point (x0) as arguments, and returns an approximation of the function root.
Example:
f(x) = x^2 − 2x + 1
f′(x) = 3x^2 − 2
x0 = −1.5
.
x3 = −1.618 = x2 − f′(x2)/f(x2)
I would appreciate a lot all of your help and suggestions.
What I have tried before is this:
newtonR f g x0 =
if (x0 - (f x0 / g x0)) /= 0 then
newtonR f g (x0 - f x0 / g x0)
else
x0
... and it returns the following error message:
No instance for (Show (Double -\> Double))
arising from a use of \`print'
(maybe you haven't applied a function to enough arguments?)