用integrate函数就可以了
具体可以见R的帮助
====================================
下面给出实例代码:
> result<-integrate(sin,0,pi)
> names(result) #查看integrate函数返回结果的元素
[1] "value" "abs.error" "subdivisions" "message" "call"
> result[1] #第一个元素是最需要了解的
$value
[1] 2
>
> integrate(sin,0,pi)
2 with absolute error < 2.2e-14
> integrate(sin,pi,0) #注意这两个结果正负号的不同
-2 with absolute error < 2.2e-14
>
> #曲线面积是要考虑正负号的:
> integrate(sin,0,2*pi) #结果接近于0
2.032977e-16 with absolute error < 4.4e-14
>
> abs.sin<-function(x)
+ {
+ return (abs(sin(x)))
+ }
>
> integrate(abs.sin,0,2*pi) #这样就得到了总面积的绝对值
4 with absolute error < 4.4e-14
>
> #自定义函数也可以求面积:
> my.fun<-function(x)
+ {
+ return (2*x+1)
+ }
>
> integrate(my.fun, 0,3)
12 with absolute error < 1.3e-13
>
https://blog.sciencenet.cn/blog-80197-221180.html
上一篇:
R 中安装语言的选择下一篇:
轻松一笑:商标委如何解释Starcraft 和 Ghost