0
$\begingroup$

I've written a simple legendre quadrature in MAPLE to compute the integral

$\int_{-1}^1 r^2 dr = \frac{r^3}{3} |_{-1}^1=\frac{2}{3}$

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

,such that

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

,which results in 0.666666635631640303. But this is only accurate up to 7 digits, even doubling the number of digits

How can I increase the accuracy of this quadrature?

$\endgroup$
1
  • 2
    $\begingroup$ Since Legendre-Gauss quadrature of order 10 would be exact for $x^2$, it's not truncation error, and since doubling the number of digits doesn't increase accuracy, it's not roundoff error. I can't replicate your results with Mathematica either. So it's likely a programming error, although I don't see it in your code. I don't have Maple, but are you absolutely sure that evalf[digits] and eval[digits] (what's the difference?) both produce sufficiently accurate results? Because the default precision seems to be 10 digits, which would be consistent with getting 7 accurate digits. $\endgroup$
    – Kirill
    Dec 23 '16 at 21:12
1
$\begingroup$

evalf evaluates using floating-point arithmetic. Increase the floating-point precision by modifying the built-in parameter Digits using the command Digits:=n.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.