Chinaunix首页 | 论坛 | 博客
  • 博客访问: 39622
  • 博文数量: 10
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2015-10-18 15:21
文章分类

全部博文(10)

文章存档

2015年(10)

我的朋友

分类: C/C++

2015-10-18 19:59:14

(1)矩阵法求定积分,积分函数f(x)=1+Exp(x)

点击(此处)折叠或打开

  1. Program main
  2. implicit none
  3. real :: a,b,x !a,b分别是下限和上限
  4. integer :: n,counter !n是分成的份数
  5. real :: step,fx !step是步长,由上限,下限,份数决定
  6. real :: area,Integral !area是小矩阵元面积,Integral 是所有矩阵元之和
  7. Integral=0.0
  8. write(*,*) "a=,b="
  9. read(*,*)a,b
  10. write(*,*) "n="
  11. read(*,*) n
  12. step=(b-a)/real(n)
  13. do counter=1,n-1,1
  14. x=a+counter*step
  15. fx=1+EXP(x)
  16. area=fx*step
  17. Integral=Integral+area
  18. end do
  19. write(*,*)"Definite Integral:",Integral
  20. stop
  21. End Program main

(2)梯形法求定积分(与矩形法没有本质区别)

点击(此处)折叠或打开

  1. Program main
  2. implicit none
  3. real :: a,b,x1,x2
  4. integer :: n,counter
  5. real :: step
  6. real :: fx1,fx2,area,Integeral
  7. Integeral=0.0
  8. write(*,*) "Input a:"
  9. read(*,*) a
  10. write(*,*) "Input b:"
  11. read(*,*) b
  12. write(*,*) "Input n:"
  13. read(*,*) n
  14. step=(b-a)/real(n)
  15. do counter=1,n-1,1
  16. x1=a+counter*step
  17. x2=x1+step
  18. fx1=1+EXP(x1)
  19. fx2=1+EXP(x2)
  20. area=0.5*(fx1+fx2)*step
  21. Integeral=Integeral+area
  22. end do
  23. write(*,*) " Integeral:",Integeral
  24. stop
  25. End Program main



阅读(1616) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~