如何提高 MAPLE 中 Gauss-Legendre 求积的精度?

计算科学 正交
2021-12-22 17:54:55

我在 MAPLE 中写了一个简单的 Legendre 求积来计算积分

11r2dr=r33|11=23

restart; with(orthopoly): with(LinearAlgebra):
legendre_quad := proc (n, digits) 
    local i, s, w, location; 
    w := Vector(n, fill = 0); 
    location := Vector(sort([evalf[digits](solve(P(n, x) = 0, x))], `<`));
    for i to n do 
        w[i] := eval[digits](2/((1-location[i]^2)*(diff(P(n, x), x))^2), [x = location[i]]) 
    end do; 
    s := (w, location) 
end proc

,这样

(weights, location) := legendre_quad(10, 50);
int := DotProduct(location^~2, weights)

,这导致0.666666635631640303但这只能精确到 7 位数,甚至翻倍digits

我怎样才能提高这个正交的准确性?

1个回答

evalf使用浮点运算进行评估。通过使用命令修改内置参数Digits来提高浮点精度Digits:=n