如何在R中使用simple方法来解决错误?

问题描述

这是我第一次尝试使用R计算表达式的导数。我尝试了以下代码

library(Ryacas)                       # open the Ryacas package.
f <- expression(asin(2*x/(1 + x^2)))  # insert the expression.
d <- D(f,'x')                        # find the expression's derivative.
print(d)                              # print the derivative of f.
simple_d <- simplify(d)               # make the mathematical expression of the derivative simpler.
print(simple_d)                       # print the simply expressed derivative of f.

我收到以下有关simplify()方法用法错误消息。

Error in UseMethod("simplify") : 
  no applicable method for 'simplify' applied to an object of class "call"

对此有何想法?我应该如何在simplify()之类的表达式上正确使用d方法

谢谢!

解决方法

使用Ryacas0,如下所示:

library(Ryacas0)                   
x <- Sym("x")
f <- asin(2*x/(1 + x^2))
d <- deriv(f,x)                   
d                             
Simplify(d)   

或像这样的Ryacas:

library(Ryacas)
x <- ysym("x")
f <- asin(2*x/(1 + x^2))
d <- deriv(f,x)
d
simplify(d)