Tuesday, April 24, 2012

Summation and Integration functions in Scheme(Higher Order Procedures)


;;######################----------------------##################33

;Higher order Procedures....
;Function for summation
(define (sigma fn a b)
  (if (> a b)
 0
 (+  (fn a)
  (sigma (+ a 1) b)
 )
  )

)

;Function for integration
(define (integral2 fn a b dx)
    (if (> a b)
 0
 (+   (fn (+ a (/ dx 2)))
      (integral fn (+ a dx) b dx)

 )
    )
)

(define (integral fn a b)
    (integral2 fn a b 0.001)
)

No comments:

Post a Comment