We have gaussian quadratures method: $$ \int\limits^\infty_0 f(x) \,\mathrm{d}x \approx \sum\limits^n_i w_i f(x_i) $$
I want to compute abscissas and the weights for various $n$ ( where $n$ will be users input) for lognormal distribution function. $$ f(x) = \frac{1}{\sqrt{2\pi}x\sigma} \exp\left( -\frac{(\ln(x) - \mu)^2}{2\sigma^2} \right) $$
We all know that integrating over the $\mathbb{R}$ we will get $1$. This is my sanity check that gaussian quadratures works fine.
My questions are:
- Which Hermite, Legendre, Laguerre quadrature should I use for my case?
- Why do I get different precision for Laguerre (best choice approach as it approximates integral $[0, \infty)$)? (Peculiar: higher $n$ gives a worse result (checked through the sci.py library)) the same - not good result (in best case $0.99978$ or something close to this) I get from Legendre and as well it is not stable. I omit Hermite, as there are negative abscissas.
- Is it normal or I can get better "quality" result?
- I started to doubt that we can freely choose $n$. I think that as result is unstable (and as I often see - result does not improve with higher $n$) the method works only for some fixed $n$, not all $n$. Why is it unstable and how can I guarantee stability?
I fail to succeed to understand this method a bit reading at wiki and other sources. So as starting point I would like to know the whole idea with this:
- What does this line in Wiki mean:
An $n$-point Gaussian quadrature rule, named after Carl Friedrich Gauss, is a quadrature rule constructed to yield an exact result for polynomials of degree $2n − 1$ or less by a suitable choice of the points $x_i$ and weights $w_i$ for $i \in \{1, \ldots, n \}$.
- Do we have in general better polynomials for particularly case of lognormal function? I do ask this because at book Numerical recipes in C, it is said that it is possible to choose for specific cases $w_i$ and $x_i$ (i.e., abscissas and weights).
I have not studied numercial methods, therefore, if there is a golden book with preferably examples, I and probably other users would be grateful to know.
Regarding your question, "what does this line in Wiki mean"
It means that the Gaussian quadrature(GQ) rule is exact for polynomials of degree $2n-1$ or less. In other words, if you integrate such a polynomial exactly and compare the result you get from GQ, there is no difference. The error is zero. This is however not the case for higher degree polynomials or other functions. In a programming language that suits you, write a code that does GQ. Consider a polynomial of degree $2n-1$ integrated from $a$ to $b$. Your result from the code should be exactly the same as what you integrate by hand. The take home message is that GQ is good since it can integrate things exactly to that degree. Other methods don't.