I have a class of integrals I need to solve numerically which have the form: $$ I_k = \int_a^b \frac{p_k(x)}{x^k} dx, \quad k = 0, 1, \dots, K $$ where $p_k(x)$ is a cubic polynomial on the interval $[a,b]$. I have tried Romberg integration which unfortunately does not produce satisfactory results. Does anyone know of a quadrature rule which can integrate these functions exactly? I would appreciate references and any existing software libraries which might help.

The coefficients of the cubic $p_k(x)$ are not readily available, as I basically call a function which produces $p_k(x)$, so its not so straightforward to calculate the above integral analytically either.

  • 3
    $\begingroup$ This integral can be taken analytically, right? But analytic solution would not work for you, you need to do it numerically? $\endgroup$ Mar 13 at 19:19
  • 1
    $\begingroup$ The polynomials $p_k(x)$ come from a cubic spline fit using a numerical library, and its not simple to access the spline coefficients directly. I could code up a workaround, but I am hoping for a simple quadrature method which can do it $\endgroup$
    – vibe
    Mar 13 at 19:24
  • 3
    $\begingroup$ If you want the integral to be exact (to the machine round-off accuracy) that means selecting the collocation points and the interpolating function in a specific way, tailored to the form of your integrand. But in the end that would not be better than reconstructing numerically the coefficients of your cubic spline function using four collocation points, and taking the integral analytically, which can certainly be done. $\endgroup$ Mar 13 at 22:04
  • 3
    $\begingroup$ Since you know that the $p_k$ are cubic, you only need four points at which to evaluate $p_k$ to obtain $p_k$ as an explicit polynomial. Then you can compute the integral exactly. You will not be able to to beat four function evaluations, whatever sophisticated quadrature formula you use :-) $\endgroup$ Mar 14 at 18:13
  • 1
    $\begingroup$ @WolfgangBangerth Four different points for each value of $k$, just to be precise. $\endgroup$ Mar 16 at 7:24

1 Answer 1


Choose four collocation points in the interval $[a,b]$, e.g.,

$ x_0=a\\ x_1=a + (1/3)(b-a)\\ x_2=a + (2/3)(b-a)\\ x_3=b $

and form a matrix $M$

\begin{bmatrix} 1 & x_0 & x_0^2 & x_0^3 \\ 1 & x_1 & x_1^2 & x_1^3 \\ 1 & x_2 & x_2^2 & x_2^3 \\ 1 & x_3 & x_3^2 & x_3^3 \\ \end{bmatrix}

Next, to find the four coefficients of the cubic spline polynomial, $\vec{C} = [c_0,c_1,c_2,c_3]^T$, use the right-hand side vector, $\vec{R} = [p_k(x_0),p_k(x_1),p_k(x_2),p_k(x_3)]^T$, and solve the linear system,

$ M \vec{C} = \vec{R} $

Finally, calculate the integral analytically integrating the cubic spline polynomial,

$ I_k = \left( c_0 \frac{x^{1-k}}{1-k} + c_1 \frac{x^{2-k}}{2-k} + c_2 \frac{x^{3-k}}{3-k} + c_3 \frac{x^{4-k}}{4-k} \right) \Bigr|_{a}^b $


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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