All pastes #2055912 Raw Edit

Mine

public text v1 · immutable
#2055912 ·published 2011-05-09 21:06 UTC
rendered paste body
(define (integrate func imin imax)
    (define (stage n)
        (let* (
            (step (/ (- imax imin) n))
            (halfStep (/ step 2.0)))
            (define (i-iter i midPoint sum)
                (define (j-iter coeffs sum)
                    (if (null? coeffs)
                        sum
                        (let ((coeff-pair (car coeffs)))
                             (j-iter (cdr coeffs)
                                 (+ sum
                                     (* (weight coeff-pair)
                                         (func (+ midPoint
                                             (* halfStep
                                                 (abscissa coeff-pair)
                                             )
                                         ))
                                     )
                                 )
                             )
                        )
                    )
                )
                (if (zero? i)
                    sum
                    (i-iter (1- i)
                        (+ midPoint step)
                        (j-iter coefficients sum)
                    )
                )
            )
            (* halfStep (i-iter n (+ imin halfStep) 0.0))
        )
    )