0

I was wondering if anyone had any advice on writing the mandelbrot stream. I have wrote the following functions for myself to help:

(define (make-complex a b) (cons a b))
(define (real-coeff c) (car c))
(define (imag-coeff c) (cdr c))
(define (c-add c d)
      (make-complex (+ (real-coeff c) (real-coeff d))
                   (+ (imag-coeff c) (imag-coeff d))))
(define (c-mult c d)
    (make-complex (- (* (real-coeff c) (real-coeff d))
                  (* (imag-coeff c) (imag-coeff d)))
               (+ (* (real-coeff c) (imag-coeff d))
                  (* (imag-coeff c) (real-coeff d)))))
(define (c-length c)
   (define (square x) (* x x))
        (sqrt (+ (square (real-coeff c))
              (square (imag-coeff c)))))

I have that fz(x) = x2 +z. The stream should return: a, fz(a), fz(fz(a)), fz(fz(fz(a))). I am confused on how to use the functions that I wrote to create a stream that has this output. Anyone have some good advice as to where to go with this?

4

2 に答える 2

3

の値から始めて、z関数fz(x)を次のようにします。

(define (make-fz z) (lambda (x) (+ z (* 2 x))))

zここで、srfi-41 ストリーム ライブラリを使用して、指定したとおりにストリームを定義します0

> (stream->list (stream-take 10 (stream-iterate (make-fz 0) 1)))
(1 2 4 8 16 32 64 128 256 512)

注:stream-iterate次のように定義されています。

(define-stream (stream-iterate fz a)
  (stream-cons a (stream-iterate fz (fz a))))
于 2013-11-20T23:18:04.843 に答える