如何在 do 循环中区分结果和前一个结果?

问题描述

该子程序用于确定复合梯形所以@H_404_1@

我想对最终结果(Integration)和前一个结果(Integeration-1)之间进行抽象(Difference),并将差异用作复制我的区间数的限制。@H_404_1@

Subroutine Trapezoid(a,b,n,integration)
real,external :: f
real :: h,a,summ,p
real,intent(out) :: integration
integer :: n
integer :: i,j
!Here as we have the whole equation is (h/2)*[f(a)+f(b)+2*sum(Xi)
!So we calculate the first part (h/2)*[f(a)+f(b) and then calculate the anoter part
do i=1,n
    n=2**i !Double the number of interval
    h=(b-a)/n  !Calculate the delta X
    p=(h/2.)*(f(a)+f(b))
        summ=0
        do j=1,n-1
            summ=summ+h*f(a+j*h)   !h/2 *2* sum[f(Xi)
        enddo  
    if(n == 256) then      !put a limit for the number of interval 
        Stop
    end if
    integration = p + summ   !Here the sum the both parts
    print*,'              ',integration 
enddo
end Subroutine

所以,而不是限制是 250 ,我想确定差异,当这个差异小于 10*-8 时,停止 我尝试了很多,但没有得到我想要的。@H_404_1@

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)