(1)矩阵法求定积分,积分函数f(x)=1+Exp(x)
-
Program main
-
-
implicit none
-
real :: a,b,x !a,b分别是下限和上限
-
integer :: n,counter !n是分成的份数
-
real :: step,fx !step是步长,由上限,下限,份数决定
-
real :: area,Integral !area是小矩阵元面积,Integral 是所有矩阵元之和
-
Integral=0.0
-
-
write(*,*) "a=,b="
-
read(*,*)a,b
-
write(*,*) "n="
-
read(*,*) n
-
step=(b-a)/real(n)
-
-
do counter=1,n-1,1
-
x=a+counter*step
-
fx=1+EXP(x)
-
area=fx*step
-
Integral=Integral+area
-
end do
-
write(*,*)"Definite Integral:",Integral
-
stop
-
-
End Program main
(2)梯形法求定积分(与矩形法没有本质区别)
-
Program main
-
-
implicit none
-
real :: a,b,x1,x2
-
integer :: n,counter
-
real :: step
-
real :: fx1,fx2,area,Integeral
-
Integeral=0.0
-
-
write(*,*) "Input a:"
-
read(*,*) a
-
write(*,*) "Input b:"
-
read(*,*) b
-
write(*,*) "Input n:"
-
read(*,*) n
-
-
step=(b-a)/real(n)
-
-
do counter=1,n-1,1
-
x1=a+counter*step
-
x2=x1+step
-
fx1=1+EXP(x1)
-
fx2=1+EXP(x2)
-
area=0.5*(fx1+fx2)*step
-
Integeral=Integeral+area
-
end do
-
-
write(*,*) " Integeral:",Integeral
-
-
stop
-
-
End Program main
阅读(1680) | 评论(0) | 转发(0) |