[Haskell-beginners] numerical integration over lists

Thomas Engel thomas.engel1 at gmx.net
Sun Feb 5 16:56:50 CET 2012


Hello Henk-Jan,
> >
> 
> The line
> >integriereListe [][]  = [0.0]
> should be
> >integriereListe [][]  = 0.0
> as the line below that calculates a number, not a list of numbers
> (that is, the type is different for that line).
thanks for the hint. I have changed the function accordingly but there is still an error for the types.

integriereListe::(Float)->(Float)->(Float)
integriereListe [][]  = 0.0
integriereListe (x:xs) (y:ys)   = (y - y2) /2 * (x2 -x)
                                 where
                                 x2 = head xs
                                 y2 = head ys
 
 Couldn't match expected type `Float' with actual type `[t0]'
    In the pattern: x : xs
    In an equation for `integriereListe':
        integriereListe (x : xs) (y : ys)
          = (y - y2) / 2 * (x2 - x)
          where
              x2 = head xs
              y2 = head ys

This are my first steps in haskell. I don't know whether my first basic approach is OK or is there a better solution for this calculation?
There is no formula to map over a list and integrate, I only have two list with values. I can zip the lists together to have a list of tuples if this is an advantage.
What I need is the first and the second value from each list, do the calculation,
the second value will become the first value of the next calculation and so on until the end of the lists.
I also need the result of the last calculation to add to the current calculation.

My calculation in excel with VBA is working, but it's quite difficult for me to do this with functional programming.

Any hints are welcome!

Thomas




More information about the Beginners mailing list