我使用D来得到一个函数的导数。但是,在返回导数时,R不会简化表达式。我需要找出一个函数是否有一个导数,可以用一般的表达式来表示。在R中有什么方法可以简化表达式吗?
> D(expression(sqrt(1 - x^2)), 'x')
-(0.5 * (2 * x * (1 - x^2)^-0.5))
> D(D(expression(sqrt(1 - x^2)), 'x'), 'x')
-(0.5 * (2 * (1 - x^2)^-0.5 - 2 * x * (-0.5 * (2 * x * (1 - x^2)^-1.5))))其次,在R中有没有一种做数值积分的方法?
发布于 2010-07-28 18:19:32
library(Ryacas)
x <- Sym("x")
Simplify(deriv(sqrt(1 - x^2),x,2)) # return the result simplified给出
expression((x^2 - 1 - x^2)/root(1 - x^2, 2)^3)您也可以尝试
PrettyForm(Simplify(deriv(sqrt(1 - x^2),x,2)))这给了我们
2 2
x - 1 - x
---------------
3
/ 2 \
Sqrt\ 1 - x / 至于数值积分,试着给出这个,看看是什么
library(sos)
findFn('{numerical+integration}')发布于 2010-07-27 14:55:59
据我所知,R不会简化D()的结果。听起来你想要一个合适的计算机代数系统,而R绝对不是一个完整的CAS。Mathematica和Maple是最广为人知的,但也有许多开源替代方案(as discussed on this SO post)。
R可以做数值积分-对于这类问题,值得首先在R帮助页面中搜索(即help.search('integrate'))。您可以在stats包中使用integrate()。MASS包中也有area(),但这要简单得多(即用于演示目的)。
https://stackoverflow.com/questions/3340690
复制相似问题