Scheme 高斯函数及其在格式中的应用
我目前正在尝试学习运行FDTD模拟的方案,但在构建二维高斯函数时遇到了困难 在一个论坛上,我发现了1D的这种可能性:Scheme 高斯函数及其在格式中的应用,scheme,gaussian,currying,Scheme,Gaussian,Currying,我目前正在尝试学习运行FDTD模拟的方案,但在构建二维高斯函数时遇到了困难 在一个论坛上,我发现了1D的这种可能性: (define ( (gaussx sigma) x) (exp (- (/ (vector3-dot x x) (* 2 sigma sigma))))) 如果我理解正确,咖喱相当于: (define (gauss sigma) (lambda(x) (exp (- (/ (vector3-dot x x) (* 2 sigma sigma)))))
(define ( (gaussx sigma) x)
(exp (- (/ (vector3-dot x x) (* 2 sigma sigma)))))
如果我理解正确,咖喱相当于:
(define (gauss sigma)
(lambda(x)
(exp (- (/ (vector3-dot x x) (* 2 sigma sigma))))))
现在我希望函数沿x和y方向都是高斯函数,但我不明白为什么这不起作用:
(define (gauss sigma)
(lambda(x)
(lambda(y)
(exp (- (/ (+ (vector3-dot y y) (vector3-dot x x)) (* 2 sigma sigma))))
当我打电话时
(gauss 1)
我得到以下信息:
ERROR: Wrong type (expecting real number): # <procedure> #f (y)
错误:错误类型(应为实数):##f(y)
有人知道我做错了什么吗?我也尝试过其他解决方案,但我似乎不明白这里的逻辑
非常感谢你的帮助
致意
Mei我认为这里不需要双咖喱,试试这个:
(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-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)
(define gauss-1 (gauss 1))
((gauss-1 some-x) some-y)