【问题标题】:integral calculator in RR中的积分计算器
【发布时间】:2020-08-29 13:51:22
【问题描述】:

我知道如何使用积分计算器获得数值,但不知道如何获得代数方程。

例如:

integrand <- function(x) {1/((x+1)*sqrt(x))}
integrate(integrand, lower = 0, upper = Inf)

使用此代码,我可以得到 3.141593 绝对错误 &lt; 2.7e-05

但是,如果我想使用这段代码怎么办:

integrand <- function(x) {2*x}
integrate(integrand, lower = -Inf, upper = Inf)

获取x^2

显然,它不起作用。

如果有人可以提供帮助,我将不胜感激。非常感谢!

【问题讨论】:

  • R 不做符号数学,但有 R 包可以做。请参阅包装 RyacasR-bloggers。另请参阅包 rSymPyhere
  • 实际上,您可以使用 Ryacas 包在 R 中进行一些有限的符号计算。见RBloggers

标签: r calculator integral


【解决方案1】:

R 不做符号数学,但有 R 包做。我将使用 CRAN 包 RyacasrSympy 给出(非常)简短的示例。

1.包Ryacas

library(Ryacas)

f <- ysym("2*x")
integrate(f, "x")
#y: x^2

2。包rSymPy

使用包rSymPy,您需要先定义符号"x"。这是通过函数 Var 完成的。
注意:在我的测试中,第一次调用Varsympy 时会给出一系列警告。我打断了R,第二次一切顺利。

library(rSymPy)

x <- Var("x")
sympy("integrate(2*x)")
#[1] "x**2"

【讨论】:

  • 谢谢你,瑞!我试过2 * x,它有效。但仍然不知道如何计算更复杂的方程。例如: library(Ryacas) f
猜你喜欢
  • 2014-03-01
  • 1970-01-01
  • 2012-02-13
  • 1970-01-01
  • 1970-01-01
  • 2019-10-08
  • 1970-01-01
  • 1970-01-01
  • 2018-04-20
相关资源
最近更新 更多