Fortran-积分

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

functionf(x)implicitnonereal*8::f,xf=dsin(x)endfunctionfprogramSimpsonimplicitnoneinteger,parameter::N=40integer::ireal*8::f!²½³¤hreal*8::h=0.1real*8::x(0:N),s,y!²åÖµµãdoi=0,Nx(i)=1+i*henddos=0!Simpson»ý·Ö¹«Ê½doi=0,N-1s=s+h/6.0*(f(x(i))+4.0*f(0.5*(x(i)+x(i+1)))+f(x(i+1)))enddoprint*,sy=cos(1.0)-cos(5.0)print*,yendprogramSimpsonfunctionf(x)implicitnonereal*8::f,xf=dsin(x)endfunctionfprogramSimpsonimplicitnoneinteger,parameter::N=40integer::ireal*8::f!²½³¤hreal*8::h1=0.1,h2=0.05real*8::x1(0:N),x2(0:2*N),s1,s2,y,error!²åÖµµãdoi=0,Nx1(i)=1+i*h1enddodoi=0,2*Nx2(i)=1+i*h2enddos1=0s2=0!Simpson»ý·Ö¹«Ê½doi=0,N-1s1=s1+h1/6.0*(f(x1(i))+4.0*f(0.5*(x1(i)+x1(i+1)))+f(x1(i+1)))enddodoi=0,2*N-1s2=s2+h2/6.0*(f(x2(i))+4.0*f(0.5*(x2(i)+x2(i+1)))+f(x2(i+1)))enddoprint*,s1print*,s2error=(s2-s1)/15.0print*,error=,errory=cos(1.0)-cos(5.0)print*,yendprogramSimpson

1 / 2
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功