辛普森 3/8 规则中的错误高于辛普森 1/3 规则

计算科学 Python 数字 一体化 误差估计
2021-12-04 18:38:23

对于给定的函数f(x),我尝试使用辛普森的 1/3辛普森的 3/8规则找到它的数值积分。

然后,我将数值积分的解与解析积分进行比较以计算误差。我发现 3/8 规则的误差是 1/3 规则的两倍,而预期的相反。我哪里做错了?

1/3 规则的 Python3 函数:

def simpsons13(a, b, N):
    """
    Calculates the numerical integral of a function f(x) using the Simpson's 1/3rd rule:

    F(x) = Σ(0 to (N-2)/2) Δx/3 * (f(x(2i)) + 4f(x(2i + 1)) + f(x(2i + 2)))

    Parameters:

    a:      The lower limit of the definite integral (real)
    b:      The upper limit of the definite integral (real)
    N:      A positive, even integer to denote the number of intervals of the function for the integral

    Returns I, the numerical integral calculated through Simpson's 1/3rd rule
    """

    if N%2 != 0:
        return "N must be even"     

    dx = (b - a)/N
    narr = np.linspace(a, b, N+1)   # N intervals corresponds to N + 1 points
    I = 0

    for i in range(int((N - 2) / 2) + 1):

        I = I + dx/3*(f(narr[2*i]) + 4*f(narr[2*i + 1]) + f(narr[2*i + 2]))

    return I

3/8 规则的 Python3 函数:

def simpsons38(a, b, N):
    """
    Calculates the numerical integral of a function f(x) using the Simpson's 3/8 rule:

    F(x) = Σ(0 to (N-3)/3) 3Δx/8 * (f(x(3i)) + 3f(x(3i + 1)) + 3f(x(3i + 2)) + f(x(3i + 3)))

    Parameters:

    a:      The lower limit of the definite integral (real)
    b:      The upper limit of the definite integral (real)
    N:      A positive, even integer to denote the number of intervals of the function for the integral

    Returns I, the numerical integral calculated through Simpson's 3/8 rule
    """

    if N%3 != 0:
        return "N must be divisible by 3"

    dx = (b - a)/N
    narr = np.linspace(a, b, N+1)
    I = 0

    for i in range(int((N-3)/3) + 1):

        I = I + 3*dx/8 * (f(narr[3*i]) + 3*f(narr[3*i + 1]) + 3*f(narr[3*i + 2]) + f(narr[3*i + 3]))

    return I 

我考虑简单的功能f(x)=xex并从中找到其数值积分[π,π]通过考虑N=24间隔。我将数值解和解析解之间的误差计算为:

error = np.abs(ans - approx)

我通过 1/3 方法得到的错误是0.003669436并通过 3/8 方法得到0.00816864. 3/8 规则的误差是 1/3 规则的两倍多。为什么会这样?

1个回答

简单的部分-[a,b]-with-midpoints 误差公式适用于 1/3 规则

E=(ba)590·25f(4)(ζ)
对于 3/8 规则
E=(ba)590·72f(4)(ζ)
现在第一个规则有 2 个子区间,而第二个规则有 3 个。要获得相等数量的函数评估的可比较值,请将其应用于具有 6 个子区间的区间,为 1/3 规则提供 3 个段,为3/8 规则。那么复合 1/3 规则的误差为
E=3·((ba)/3)590·25f(4)(ζ)=(ba)590·25·34f(4)(ζ)=((ba)/6)530f(4)(ζ)
和复合 3/8 规则
E=2·((ba)/2)590·72f(4)(ζ)=(ba)540·25·34=((ba)/6)540/3f(4)(ζ)
中点ζ每个公式都可以并且将会有所不同。

总共 3/8 规则的误差约为94相同数量的采样点的 1/3 规则的误差。这也正是您观察到的,因为36·94=81.


请注意,如果将其扩展为 Runge-Kutta 方法,其中“经典”方法基于 1/3 规则,3/8 方法基于 3/8 规则,这两种方法都有 4 个阶段,即 4 个函数评价。这意味着两种方法都可以基于单段误差公式进行比较,因此 3/8 方法的步长误差较小。(必须通过实际的一步龙格-库塔错误来确认这一点,库塔在原始论文中确实已经完成了这一点。)