在 R 编程中计算函数的单阶积分值 - 积分()函数
R语言中的integrate()
函数用于计算所提供函数的单阶积分。
Syntax: integrate(f, lower, upper)
Parameters:
f: represents a function
lower: represents lower limit of integration
upper: represents upper limit of integration
要了解更多选项参数,请使用以下命令:
help("integrate")
示例 1:
# Create function
f<-function(x) x^3 + 2*x
# Integrate from 0 to 1
integrate(f, 0, 1)
输出:
1.25 with absolute error < 1.4e-14
示例 2:
# Create function
f <- function(x) {1/((x+1)*sqrt(x))}
# Integrate from 0 to 5
integrate(f, lower = 0, upper = 5)
输出:
2.300524 with absolute error < 0.00011