Gaussian Quadrature Question

In summary, the conversation discusses the creation of a generalized quadrature method and the occurrence of errors while trying to implement it. The algorithm involves using the nth legendre polynomial, a function to integrate, and weights and roots based on the value of n. The speaker has checked their code and believes it to be correct, but wonders if they have made a mistake in implementing the Gaussian quadrature algorithm. They mention writing their code in Haskell and request assistance.
  • #1
valis
1
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
[itex]g = x \rightarrow f\left(\frac{b-a}{2}x+\frac{b+a}{2}\right)[/itex] where f is the function to integrate
xs = n roots of p
ws = weights based on value of n (2 => +/-0.57735026918963)
[itex]\frac{b-a}{2}\sum^n_0{w_ig(x_i)}[/itex]

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
  • #2
I suggest you try it with f(x)=1 and see what the weights are.
 
  • #3


It sounds like you may have made a mistake in your implementation of the Gaussian quadrature algorithm. It's always a good idea to double check your code and make sure it matches the pseudo-code you are following. In particular, you may want to check the calculation of the weights, as those seem to be the source of your error.

Another possibility is that your function f is not well-behaved enough for the Gaussian quadrature method to work accurately. This method is best suited for integrating smooth, continuous functions. If your function has discontinuities or rapidly changing behavior, it may not give accurate results.

I would suggest trying to debug your code and also experimenting with different functions to see if the issue persists. Good luck!
 

What is Gaussian Quadrature Question?

Gaussian Quadrature Question is a mathematical problem that involves finding numerical approximations for definite integrals. It is used to solve integration problems that cannot be solved analytically.

How is Gaussian Quadrature Question different from other numerical integration methods?

Gaussian Quadrature Question is different from other numerical integration methods because it uses specific weights and nodes to accurately approximate the integral, rather than dividing the interval into smaller subintervals. This results in a more accurate and efficient solution.

What is the main advantage of using Gaussian Quadrature Question?

The main advantage of using Gaussian Quadrature Question is that it provides highly accurate solutions for definite integrals, even for complex functions. It also requires fewer function evaluations compared to other numerical integration methods, making it computationally efficient.

What are the limitations of Gaussian Quadrature Question?

Gaussian Quadrature Question is not suitable for all types of integrals, as it is designed to work best with smooth and continuous functions. It may also be less accurate for integrals with rapidly changing functions or highly oscillatory behavior.

How is the accuracy of Gaussian Quadrature Question determined?

The accuracy of Gaussian Quadrature Question depends on the number of nodes used in the approximation. Generally, the more nodes that are used, the more accurate the solution will be. Additionally, the choice of weights and nodes also affects the accuracy of the solution.

Similar threads

  • Calculus
Replies
2
Views
1K
Replies
18
Views
2K
  • Linear and Abstract Algebra
Replies
4
Views
833
  • Advanced Physics Homework Help
Replies
6
Views
1K
Replies
4
Views
1K
  • Calculus and Beyond Homework Help
Replies
4
Views
2K
Replies
2
Views
410
Replies
16
Views
2K
Replies
6
Views
885
Replies
1
Views
2K
Back
Top