tags:

views:

212

answers:

1
 (define (Integral f a b N)  
    ;define h as a constant
    (let((h (/ (- b a) N))))       
     (define (Term n)   
      (* (/ h 3) (+ (* 2 (f (+ a (* 2 (* n h)))))   
            (* 4 (f (+ a (* 2 (* (- n 1) h)))))  
            )  
     ))  
     (+ (* (/ h 3) (+ (f a) (f b))) (sum Term a next (/ N 2.0))))  

This code produces an error r5rs:body: no expression in body in: (r5rs:body) Could you please help?

+4  A: 

You misplaced the braces after the let. After you defined a constant in let the code that uses the constant has to be inside of the let's scope. Hence your error about missing the body of the expression.

Here is the corrected code

    (define (Integral f a b N)
    ;define h as a constant (let((h (/ (- b a) N))))
    (let((h (/ (- b a) N)))
      (define (Term n)
      (* (/ h 3) (+ (* 2 (f (+ a (* 2 (* n h)))))
      (* 4 (f (+ a (* 2 (* (- n 1) h)))))
      )
      )) 
      (+ (* (/ h 3) (+ (f a) (f b))) (sum Term a next (/ N 2.0)))
     )
    )

BTW, you still need to define the sum function.

Vlad
Thank you!! You saved me a lot of wasted time. It was my first let expression!!FYI, For sum I was using ;give two functions term and next we can compute sum in the ;range a to b(define (sum term a next b) (if (> a b) 0 (+ (term a) (sum term (next a) next b))))
test11