2

I am currently trying to learn Scheme to run FDTD simulations and I am having trouble building a Gaussian function in 2 dimensions.

In a forum I found this possibility for 1D:

(define ( (gaussx sigma) x)
   (exp (- (/ (vector3-dot x x) (* 2 sigma sigma)))))

which if I understood currying correctly is equivalent to:

(define  (gauss sigma)
   (lambda(x)
      (exp (- (/ (vector3-dot x x) (* 2 sigma sigma))))))

Now I would like the function to be gaussian along both x and y directions but I don't understand why this doesn't work:

(define  (gauss sigma)
   (lambda(x)
      (lambda(y)
         (exp (- (/ (+ (vector3-dot y y) (vector3-dot x x)) (* 2 sigma sigma))))

When I call

(gauss 1)

I get the following message:

ERROR: Wrong type (expecting real number): # <procedure> #f (y)

Does someone see what I am doing wrong? I also tried other solutions but I don't seem to get the logics here...

Thanks a lot for your help!

Best regards Mei

4

1 回答 1

1

我认为这里不需要双重咖喱,试试这个:

(define (gauss sigma)
  (lambda (x y)
    (exp (- (/ (+ (vector3-dot y y) (vector3-dot x x)) (* 2 sigma sigma))))))

像这样称呼它:

(define gauss-1 (gauss 1))
(gauss-1 some-x some-y)

但是如果你肯定需要双重咖喱,这应该工作:

(define (gauss sigma)
  (lambda (x)
    (lambda (y)
      (exp (- (/ (+ (vector3-dot y y) (vector3-dot x x)) (* 2 sigma sigma)))))))

像这样使用它:

(define gauss-1 (gauss 1))
((gauss-1 some-x) some-y)
于 2013-01-23T15:35:19.350 回答