【问题标题】:Scheme Derivative Function方案导数函数
【发布时间】:2013-09-17 16:31:06
【问题描述】:

我今天在scheme中写了一个简单的导函数。我被要求返回一个函数,例如 g(x) = (f (x+h) -f(x))/h 。这足以返回一个函数还是只返回一个值?

(define (der f h)
 (lambda (x)
 (/ (- (f(+ x h)) (f x)) h)))    

【问题讨论】:

    标签: scheme derivative


    【解决方案1】:

    是的,问题中的代码正在返回一个函数(这就是 lambda 的用途)。如果它返回一个,它将丢失带有(lambda (x) 的行和相应的右括号。

    还要注意,虽然程序是正确的,但问题中的公式是不对的,应该是:

    g(x) = (f(x+h) - f(x))/h ; notice that x is the parameter to the second call to f
    

    附带说明,使用定义的导数函数的正确方法是:

    (define der-sqr (der square 1e-10)) ; create the derivative *function*
    (der-sqr 10)                        ; apply the function
    => 20.000072709080996
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 2013-09-22
      • 2020-07-04
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多