QuadGK.jl icon indicating copy to clipboard operation
QuadGK.jl copied to clipboard

A question regarding quadrature rules for the weight function w(x)=1/(1+x^2)

Open nhavt opened this issue 4 years ago • 2 comments

Hi there,

I would like to ask you a question regarding quadrature rules for the weight function w(x)=1/(1+x^2). I hope this is fine to post my question here. My question is that I would like to compute the integral I = \int_{a}^{b} w(x)f(x)dx using quadrature rules, where w(x) is a weight function and f(x) can be approximated by a polynomial of degree 2N−1 or less on [a, b]. This is because it is costly to compute f(x). Therefore, I am looking for a quadrature rule for the weight function w(x)=1/(1+x^2). I had a look at https://en.wikipedia.org/wiki/Gaussian_quadrature. However, I could not find a quadrature rule for the weight function that I need. But I found that your package can compute the integral I for arbitrary weight functions. So, do you think that it is fine that I use the function "QuadGK.gauss" to obtain the quadrature points x[i] and weights w[i] and can compute the integral I from sum(w .* f.(x)). Or do you have any suggestions for me? Thank you very much in advance!

nhavt avatar Apr 23 '21 12:04 nhavt

What is your interval (a,b)?

  • If the interval includes x=±1, where your w(x) blows up, then your integral does not converge (unless f vanishes at these points), because this is not an integrable singularity. For the same reason, QuadGK.gauss will not work for this weight function.
  • Or maybe you want to compute a Cauchy Principal value? In that case, you can use a simple transformation to remove the singularity: https://github.com/JuliaMath/QuadGK.jl/pull/44#issuecomment-590606772
  • If your interval does not include the singularity, why do you need to precompute the effect of the weight function at all? Why not just pass the whole integrand F(x)=w(x)f(x) to quadgk or some other quadrature method? But yes, you could use QuadGK.gauss to obtain a custom weighted quadrature scheme in this case.

stevengj avatar Apr 23 '21 21:04 stevengj

Hi @stevengj,

Thank you very much for your help. So, my interval can arbitrarily be chosen (a, b>=0).

If the interval includes x=±1, where your w(x) blows up, then your integral does not converge (unless f vanishes at these points), because this is not an integrable singularity. For the same reason, QuadGK.gauss will not work for this weight function.

Do you mean that at these values my w(x) will equal to 0? But I think w(x)=1/(1+x^2) = 1 when x=+-1.

Or maybe you want to compute a Cauchy Principal value? In that case, you can use a simple transformation to remove the singularity: #44 (comment)

Yes, indeed. That is what I want. Here my weight function could be (1)w(x) = e^{-x^2} (normal distribution) or (2) w(x) = 1/(1+x^2) (Half-Cauchy distribution, https://distribution-explorer.github.io/continuous/halfcauchy.html). In case (1), we can use Gauss–Laguerre quadrature (https://en.wikipedia.org/wiki/Gauss–Laguerre_quadrature). But in case (2), I could not find a proper a quadrature rule (see https://en.wikipedia.org/wiki/Gaussian_quadrature in Section "Other Forms"). Perhaps, I would need to do a transformation as you suggested to remove the singularity. Or another transformation is x = tan(u). So my integral will be I = \int_{a}^{b} w(x)f(x)dx = \int_{arctan(a)}^{arctan(b)} f(tan(u))du. Then, I can use your function QuadGK.gauss to get notes and weights. I am sorry that I do not know how to display LaTeX formulaes in GitHub.

If your interval does not include the singularity, why do you need to precompute the effect of the weight function at all? Why not just pass the whole integrand F(x)=w(x)f(x) to quadgk or some other quadrature method? But yes, you could use QuadGK.gauss to obtain a custom weighted quadrature scheme in this case.

Yes, indeed. I also thought that. But I thought that using QuadGK.gauss on F(x) might not give a good approximation compared to a special technique using different polynomials on w(x). So, I will try with your suggestions. Also, do you have any suggestions for other quadrature methods that I could look at?

Thank you very much for your help!

nhavt avatar Apr 24 '21 15:04 nhavt