我想知道是否有人对编写mandelbrot流有任何建议。我为自己编写了以下函数以提供帮助:
(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)))))
我有fz(x)=x2+z。流应该返回:a,fz(a),fz,fz。我对如何使用我编写的函数来创建具有此输出的流感到困惑。有人有什么好建议吗?
从z
的值开始,使函数fz(x)
类似于:
(define (make-fz z) (lambda (x) (+ z (* 2 x))))
现在,使用srfi-41流库,定义一个流,正如您所指出的:试用(使用0
的z
):
> (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))))
正如uselpa所说,Scheme有内置的复数。您提到的功能如下:
make-rectangular
real-part
imag-part
+
*
magnitude
关于你问题的第二部分,什么是z
?如果不知道自己想要什么,很难回答这个问题。