sicp-3-5-4-3-5-5

Posted on 2015-03-05 06:11:43 +0900 in SICP Lisp

3.77

 (define (integral delayed-integrand initial-value dt)
   (cons-stream
     initial-value
     (let ((integrand (force delayed-integrand)))
       (if (stream-null? integrand)
         the-empty-stream
         (integral
           (delay (stream-cdr integrand))
           (+ (* dt (stream-car integrand)) initial-value)
           dt)))))

3.78

 (define (integral delayed-integrand initial-value dt)
   (cons-stream
     initial-value
     (let ((integrand (force delayed-integrand)))
       (if (stream-null? integrand)
         the-empty-stream
         (integral
           (delay (stream-cdr integrand))
           (+ (* dt (stream-car integrand)) initial-value)
           dt)))))
(define (solve-2nd a b dt y0 dy0)
  (define y (integral (delay dy) y0 dt))
  (define dy (integral (delay ddy) dy0 dt))
  (define ddy
    (add-streams
      (scale-stream dy a)
      (scale-stream y b)))
  y)

3.79

 (define (general-solve-2nd f y0 dy0 dt)
   (define y (integral (delay dy) y0 dt))
   (define dy (integral (delay ddy) dy0 dt))
   (define ddy (stream-map f dy y))
   y)
----------------------------------- 本文内容遵从CC版权协议转载请注明出自kamelzcs -----------------------------------
«  | sicp-3-5-3 »

Hide Comments

comments powered by Disqus