Trying a couple different ways of implementing Newtons Method, but I cant seem to get it working. It's most likely a very simple fix, but I just need someone to point out what I'm doing wrong. Yeah I know my code is ugly, just messing around right now.
In this example, I just try to make an equation for xn+1, which isn't working.
function :: (Num a) => a -> a
function x = 98 - x^98
function' :: (Num a) => a -> a
function' x = (-98)*(x^97)
xi = 1.04
iterations = 20
newtons :: (Integral a) => a -> a
newtons x = x - fromIntegral ( div (function x) (function' x) )
When I type 'newtons xi' in ghci I get an error that says "no instance for Integral Double arising from a use of newtons". What type class should I be using to make this work?
xiis aDouble, but you're passing it in tonewtons, which expects anIntegral atype.Doubleis not anIntegraltype. Why are you converting toIntegralanyway? It has no relevance in the context of Newton's method. - bheklilrdiv. You probably need to useFractionalrather thanNum, since then you can use/. - bheklilr