| 5 | 1/1 | 返回列表 |
| 查看: 1538 | 回復(fù): 4 | ||
fgwei2000銅蟲(chóng) (正式寫(xiě)手)
|
[求助]
我編的Simpson積分法fortran程序給不出結(jié)果,大俠們看看哪里出了問(wèn)題?
|
|
如題:我編的Simpson積分法fortran程序給不出結(jié)果,大俠們看看哪里出了問(wèn)題? 線性函數(shù)f=x在區(qū)間【0,1】上的積分,結(jié)果0.5.[ Last edited by fgwei2000 on 2011-10-29 at 23:07 ] |
金蟲(chóng) (正式寫(xiě)手)
迷途書(shū)蟲(chóng)

金蟲(chóng) (正式寫(xiě)手)
迷途書(shū)蟲(chóng)
|
建議參考下列代碼 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 |

銅蟲(chóng) (正式寫(xiě)手)
銅蟲(chóng) (正式寫(xiě)手)
| 5 | 1/1 | 返回列表 |
| 最具人氣熱帖推薦 [查看全部] | 作者 | 回/看 | 最后發(fā)表 | |
|---|---|---|---|---|