24小时热门版块排行榜    

查看: 1459  |  回复: 4
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

fgwei2000

铜虫 (正式写手)

[求助] 我编的Simpson积分法fortran程序给不出结果,大侠们看看哪里出了问题?

如题:我编的Simpson积分法fortran程序给不出结果,大侠们看看哪里出了问题?
线性函数f=x在区间【0,1】上的积分,结果0.5.[ Last edited by fgwei2000 on 2011-10-29 at 23:07 ]
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingxb

金虫 (正式写手)

迷途书虫

【答案】应助回帖

★ ★
余泽成(金币+2): 谢谢参与应助! 2011-11-02 10:38:51
你这个Simposon积分法看上好去好奇怪。

你两次求差的目的是不是要判断是否达到要求的精度?

但是你在Sn 和S2n的计算公式貌似和普通的公式不同,建议重新检查所有公式。
http://sites.google.com/site/nwnuatom/个人网站,欢迎猛击乱点!
2楼2011-11-01 14:54:30
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

dingxb

金虫 (正式写手)

迷途书虫

【答案】应助回帖

fgwei2000(金币+2): 2011-11-01 22:10:32
建议参考下列代码


Program Simpsons
implicit none

real, Parameter :: a=0,b=1
integer :: n_points
integer :: k,i
real :: approx
real :: del_x, height, area, t,x
real :: n_points_1

Write(*,*)'Enter number of points'
Read(*,*)n_points

n_points_1 = real(n_points)

del_x = abs(b-a)/(n_points_1-1.)


approx = 0
t = a

do k=1, n_points-1

x = t + del_x/2
area = del_x/6 * ( 4*functio_n ( x ) + functio_n(t) + functio_n(t+del_x) )
t = t + del_x

approx = approx + area

end do



Write(*,*)approx


Contains
Real Function functio_n(x)
Real, Intent(in) :: x
functio_n=exp(-x)
end function

end program
http://sites.google.com/site/nwnuatom/个人网站,欢迎猛击乱点!
3楼2011-11-01 14:59:13
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 fgwei2000 的主题更新
信息提示
请填处理意见