【问题标题】:How do I get the derivative of the function?如何获得函数的导数?
【发布时间】:2016-09-26 23:20:03
【问题描述】:

如何得到以下函数的导数?

g <- expression(x^2)
derivg <- D(g, 'x')
derivg
# 2 * x
g1 <- derivg(2)
# Error: could not find function "derivg"

我想求 x = 2 处的导数。

【问题讨论】:

  • 您查看过?D 帮助页面吗?他们有一些非常清楚的例子。

标签: r derivative differentiation


【解决方案1】:

derivg 是一个调用,而不是一个函数。要在x = 2 评估它,您可以这样做

eval(derivg, list(x = 2))
[1] 4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-08
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    • 1970-01-01
    相关资源
    最近更新 更多