Why Is My Gaussian Quadrature Implementation Inaccurate?

Click For Summary
SUMMARY

The forum discussion centers on the inaccuracies encountered in a Gaussian quadrature implementation using Haskell. The user reports that for n=2, the computed result is double the expected value, and inaccuracies worsen as n increases. The algorithm involves the nth Legendre polynomial, transformation of the function to integrate, and the use of specific weights for the roots of the polynomial. Despite verifying the correctness of the Legendre functions and roots, the user seeks clarification on potential errors in their Gaussian quadrature algorithm.

PREREQUISITES
  • Understanding of Gaussian quadrature methods
  • Familiarity with Legendre polynomials
  • Proficiency in Haskell programming
  • Knowledge of numerical integration techniques
NEXT STEPS
  • Review the derivation of Gaussian quadrature weights and nodes
  • Explore the implementation of Legendre polynomials in Haskell
  • Investigate common pitfalls in numerical integration algorithms
  • Test the Gaussian quadrature implementation with various functions beyond f(x)=1
USEFUL FOR

Mathematicians, computer scientists, and software developers involved in numerical analysis, particularly those implementing Gaussian quadrature methods in programming languages like Haskell.

valis
Messages
1
Reaction score
0
I'm trying to make a generalized quadrature method and I seem to be running into some bizarre errors. For n=2 my answer is twice what it should be and for n greater the innaccuracy increases (answer/n is close but worse than answer/2 with n=2). My general algorithm is:
p = nth legendre polynomial
g = x \rightarrow f\left(\frac{b-a}{2}x+\frac{b+a}{2}\right) where f is the function to integrate
xs = n roots of p
ws = weights based on value of n (2 => +/-0.57735026918963)
\frac{b-a}{2}\sum^n_0{w_ig(x_i)}

I've checked my generation of legendre functions and they're consistently correct. I also generated a list of roots and verified some against wikipedia's list. Have I stupidly mangled the actual gaussian quadrature algorithm?

I'm writing this in haskell so my code is 1:1 with the pseduo-code above.

Thanks ahead for the help.

Sorry if this is in the wrong forum, it's not coursework, but it is academic.
 
Last edited:
Physics news on Phys.org
I suggest you try it with f(x)=1 and see what the weights are.
 

Similar threads

Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 4 ·
Replies
4
Views
2K