计算机fortran课程设计(1) 下载本文

n=100时梯形法运行结果

n=1000时梯形法运行结果

n=5000时梯形法运行结果

3、辛普生法: 程序编写如下:

real a,b,s integer n real sinpson

print*,'输入a,b和n的值' read*,a,b,n

s=sinpson(a,b,n) print 10,a,b,n print 20,s

10 format('a=',f5.2,3x,'b=',f5.2,3x,'n=',i4) 20 format('s=',f15.8) end

real function sinpson(a,b,n) implicit none real a,b,h,f2,f4,x integer i,n real func

h=(b-a)/(2.0*n) x=a+h f2=0

f4=func(x) do i=1,n-1 x=x+h

f2=f2+func(x) x=x+h

f4=f4+func(x) enddo

sinpson=(func(a)+func(b)+4.0*f4+2.0*f2)*h/3.0 end

real function func(x) real x

func=1+sin(x) end

n=10时辛普生法运行结果

n=100时辛普生法运行结果

n=1000时辛普生法运行结果

n=5000时辛普生法运行结果 三、利用Gauss-Jordan法求联立方程组:

{ x+4y+7z=12 2x+5y+8z=15 3x+6y+8z=17