盛开的金达莱分享 http://blog.sciencenet.cn/u/lobo 贾鹏,又名金在日,朴依生,金罗布,艾哈迈迪·萨利米

博文

在R中求曲线面积的积分

已有 13909 次阅读 2009-3-18 22:14 |个人分类:未分类|系统分类:科研笔记|关键词:学者| 面积, 曲线, 积分

用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://m.sciencenet.cn/blog-80197-221180.html

上一篇:R 中安装语言的选择
下一篇:轻松一笑:商标委如何解释Starcraft 和 Ghost

1 黄富强

发表评论 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-23 19:47

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部