我想知道是否有人对写曼德尔布罗特河有什么建议。我为自己编写了以下函数以提供帮助:
(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)))))流应该返回: a,fz(a),fz(A))。对于如何使用我编写的函数来创建具有此输出的流,我感到困惑。有谁能给我一些好的建议,告诉他们该怎么做?
发布于 2013-11-20 23:18:04
从z的值开始,并使您的函数fz(x)如下:
(define (make-fz z) (lambda (x) (+ z (* 2 x))))现在,使用srfi-41流库,按照您的指示定义一个流:尝试它(使用z of 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-20 19:51:07
正如uselpa所说,Scheme已经内置了复数。您提到的功能如下:
make-rectangularreal-partimag-part+*magnitude至于你问题的第二部分,什么是z?在不知道你想要什么的情况下很难回答这个问题。
https://stackoverflow.com/questions/20105436
复制相似问题