# Need a fast way to evaluate these integrals

Undoubtedly, this question is so easy but I'd like to ask it. We know that the way in which the indefinite integrals like $\int P(x)e^{ax}dx$ and $\int P(x)\sin(bx)dx$ wherein $P(x)$ is an arbitrary polynomial of $x$ and $a, b\in \mathbb R$ are evaluated is Integrating by Parts $\int udv=uv-\int vdu$.

So we should take $u$ and $dv$ frequently until the whole integral becomes an easy integral. Is there any fast method in which we can do above integrals without using the classic formula? Thank you for the help.

-

I know two tricks. For the $\sin(bx)$ type of integral, notice that $P(x)\sin(bx)$ is the imaginary part of $P(x)e^{ibx}$, which you can integrate more easily and then extract the imaginary part.

For the $e^{ax}$ type, notice that $x^ne^{ax} = \frac{\partial^n}{\partial a^n}(e^{ax})$. So then $$\int x^n e^{ax}dx = \int \frac{\partial^n}{\partial a^n}e^{ax}dx = \frac{\partial^n}{\partial a^n} \int e^{ax} dx$$  $$= \frac{\partial^n}{\partial a^n}\left(\frac{1}{a}\right) = \frac{(-1)^n}{n! a^{n+1}}$$if you're integrating from 0 to infinity.

-
Sorry to be picky, but you don't solve integrals, you evaluate integrals. –  Stefan Smith Jun 8 '12 at 11:50
@user20520: oh thanks, sorry too. :-) –  Babak S. Jun 8 '12 at 12:00

We know $$\int P(x)e^{ax}\,dx=Q(x)e^{ax}+C$$ for some polynomial $Q(x)$ of the same degree as $P(x)$ (the coefficients of $Q$ may also involve $a$). Differentiating, $P(x)e^{ax}=(aQ(x)+Q'(x))e^{ax}$, so $$P(x)=aQ(x)+Q'(x)$$ Now you can use this to find the coefficients of $Q$ one at a time, starting with the leading coefficient and working your way down the degrees.

For example, to find $\int(3x^2+4x+5)e^{6x}\,dx$, let $Q(x)=rx^2+sx+t$; then $$aQ(x)+Q'(x)=6rx^2+(6s+2r)x+(6t+s)$$, so comparing coefficients we get $$3=6r;\qquad4=6s+2r;\qquad5=6t+s$$ and you get $r$ from the first equation, $s$ from the second, and $t$ from the third.

For the trig integral, you can use Jack's idea (but I think Jack meant $e^{ibx}$), or you can say that the answer will be of the form $Q(x)\sin(bx)+R(x)\cos(bx)$ and solve as above, noting that of the two polynomials $Q$ and $R$ one has only even, the other only odd, degree terms.

-

Note that the solution to $$(D+a)u=f\tag{1}$$ is computed, using integrating factors, to be $$u(x)=e^{-ax}\int f(x)\,e^{ax}\,\mathrm{d}x\tag{2}$$ Therefore, by inverting $(1)$, we get \begin{align} u(x) &=\frac{1}{D+a}f(x)\\ &=\frac1a\sum_{k=0}^\infty\left(\frac{-D}{a}\right)^kf(x)\tag{3} \end{align} whenever the infinite sum in $(3)$ makes sense, which it does in the case of polynomials.

Equating $(2)$ and $(3)$, we get $$\int f(x)\,e^{ax}\,\mathrm{d}x=\frac{e^{ax}}{a}\sum_{k=0}^\infty\left(\frac{-D}{a}\right)^kf(x)\tag{4}$$ at least when $f$ is a polynomial.

Let $a=ib$ above and we get $$\int f(x)(\cos(bx)+i\sin(bx))\,\mathrm{d}x=\frac{\sin(bx)-i\cos(bx)}{b}\sum_{k=0}^\infty\left(\frac{iD}{b}\right)^kf(x)\tag{5}$$ and after separating real and imaginary parts, we get $$\small\int f(x)\cos(bx)\,\mathrm{d}x=\left[\frac{\sin(bx)}{b}\sum_{k=0}^\infty(-1)^k\left(\frac{D}{b}\right)^{2k}+\frac{\cos(bx)}{b}\sum_{k=0}^\infty(-1)^k\left(\frac{D}{b}\right)^{2k+1}\right]f(x)\tag{6}$$ and $$\small\int f(x)\sin(bx)\,\mathrm{d}x=\left[\frac{\sin(bx)}{b}\sum_{k=0}^\infty(-1)^k\left(\frac{D}{b}\right)^{2k+1}-\frac{\cos(bx)}{b}\sum_{k=0}^\infty(-1)^k\left(\frac{D}{b}\right)^{2k}\right]f(x)\tag{7}$$

-

I'll show that

$$\int {{\text{P}}(x){e^{ax}}dx} = e^{ax}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac 1 {a^{k+1}}\frac{{{d^k}}}{{d{x^k}}}\left( {{\text{P}}\left( x \right)} \right)} + C$$

where $n=\deg P$

We start by

$$\mathrm I(n)=\int x^n e^x dx$$

Integration by parts will give you

$$\int x^n e^x dx =x^n e^x-n\int x^{n-1}e^xdx$$

that is

$$\mathrm I(n)=x^ne^x-n\mathrm I(n-1)$$

Induction gives:

$${\text{I}}(n) = {x^n}{e^x} - n{x^{n - 1}}{e^x} + n\left( {n - 1} \right){x^{n - 2}}{e^x} + \cdots + {\left( { - 1} \right)^k}n\left( {n - 1} \right) \cdots \left( {n - k + 1} \right){x^{n - k}}{e^x} + {\left( { - 1} \right)^{k + 1}}n\left( {n - 1} \right) \cdots \left( {n - k} \right)I\left( {n - k - 1} \right)$$

I guess you note that all but the last term is $e^x$ times $\dfrac{d^k}{dx^k}(x^n)$

We choose $k=n-1$ to get the following:

$${\text{I}}(n) = {x^n}{e^x} + {\left( { - 1} \right)^1}\frac{d}{{dx}}\left( {{x^n}} \right){e^x} + \cdots + {\left( { - 1} \right)^{n - 1}}\frac{{{d^{n - 1}}}}{{d{x^{n - 1}}}}\left( {{x^n}} \right){e^x} + {\left( { - 1} \right)^n}n!I\left( 0 \right)$$ $${\text{I}}(n) = {x^n}{e^x} + {\left( { - 1} \right)^1}\frac{d}{{dx}}\left( {{x^n}} \right){e^x} + \cdots + {\left( { - 1} \right)^{n - 1}}\frac{{{d^{n - 1}}}}{{d{x^{n - 1}}}}\left( {{x^n}} \right){e^x} + {\left( { - 1} \right)^n}n!{e^x} + C$$

We can put that under a sum, more nicely: $${\text{I}}(n) = {e^x}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{{{d^k}}}{{d{x^k}}}\left( {{x^n}} \right)} + C$$

Surely, we can now think about $e^{ax}$. We have

\eqalign{ & {\text{J}}(n) = \int {{x^n}{e^{ax}}dx} = \frac{1}{{{a^{n + 1}}}}\int {{{\left( {ax} \right)}^n}{e^{ax}}d\left( {ax} \right)} = \frac{1}{{{a^{n + 1}}}}\int {{u^n}{e^u}du} \cr & {\text{J}}(n) = \frac{1}{{{a^{n + 1}}}}{e^u}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{{{d^k}}}{{d{u^k}}}\left( {{u^n}} \right)} + C \cr & {\text{J}}(n) = \frac{1}{{{a^{n + 1}}}}{e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{{{d^k}}}{{d{{\left( {ax} \right)}^k}}}\left( {{a^n}{x^n}} \right)} + C \cr & {\text{J}}(n) = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}\left( {{x^n}} \right)} + C \cr}

Now that we have this, we can consider an arbitrary polinomial in $x$:

$$\mathrm P(x)=p_nx^n+p_{n-1}x^{n-1}+\cdots+p_1x+p_0$$

Since the polynomial is a linear comination of powers of $x$, and both the integral and the derivative are linear operators, we have

$$\int {{\text{P}}(x){e^{ax}}dx} = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} + C$$

Note the interesting result. The operator

$$\mathrm I = \int {\left( \text{ } \cdot \text{ } \right){e^{ax}}dx}$$

is equivalent to the operator

$${\text{D}} = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}\left( {{\text{ }}\cdot{\text{ }}} \right)}$$

for a polynomial $\mathrm P(x)$ where $n=\deg P$

To evaluate $$\int {P\left( x \right)\sin bxdx}$$ and $$\int {P\left( x \right)\cos xdx}$$

recall the last result:

$$\int {P\left( x \right){e^{ax}}dx} = {e^{ax}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{a^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)}$$

and Euler's Formula:

$${e^{ibx}} = \cos bx + i\sin bx$$

Then let $a=bi$ and get

$$\int {P\left( x \right){e^{ax}}dx} = {e^{bix}}\sum\limits_{k = 0}^n {{{\left( { - 1} \right)}^k}\frac{1}{{{{\left( {ib} \right)}^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} = - {e^{bix}}\sum\limits_{k = 0}^n {\frac{{{i^{k + 1}}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)}$$

We only need to address the powers of $i$. We need to split

$$\sum\limits_{k = 0}^n {\frac{{{i^k}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)}$$

into its real and imaginary parts. Assume that $n=2m$ (ie the polynomial is of even degree). We can write

$$\sum\limits_{k = 0}^n {\frac{{{i^k}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} = \sum\limits_{k = 0}^m {\frac{{{i^{2k}}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} + \sum\limits_{k = 0}^{m - 1} {\frac{{{i^{2k + 1}}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)}$$

$$\sum\limits_{k = 0}^n {\frac{{{i^k}}}{{{b^{k + 1}}}}\frac{{{d^k}}}{{d{x^k}}}{\text{P}}\left( x \right)} = \sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} + i\sum\limits_{k = 0}^{m - 1} {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)}$$

This gives

\eqalign{ & \int {P\left( x \right)\sin bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^{m - 1} {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)} \cr & \int {P\left( x \right)\cos bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} \cr}

If $n = 2m + 1$ we'd get

\eqalign{ & \int {P\left( x \right)\sin bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 2}}}}\frac{{{d^{2k + 1}}}}{{d{x^{2k + 1}}}}{\text{P}}\left( x \right)} \cr & \int {P\left( x \right)\cos bxdx} = \left( {\sin bx - \cos bx} \right)\sum\limits_{k = 0}^m {\frac{{{{\left( { - 1} \right)}^k}}}{{{b^{2k + 1}}}}\frac{{{d^{2k}}}}{{d{x^{2k}}}}{\text{P}}\left( x \right)} \cr}

-

With $Q$ and $P$ as in Gerry's answer, you can write $Q = a^{-1} P - a^{-2} P' + a^{-3} P'' - \ldots$ (stopping when the derivatives become $0$). Thus in his example with $P = 3 x^2 + 4 x + 5$ and $a = 6$, $$Q = \frac{3 x^2 + 4 x + 5}{6} - \frac{6 x + 4}{6^2} + \frac{6}{6^3} = \frac{x^2}{2} + \frac{x}{2} + \frac{3}{4}$$

Similarly, $\int P(x) \sin(bx)\ dx = Q(x) \sin(bx) + R(x) \cos(bx)$ where \eqalign{Q &= b^{-2} P' - b^{-4} P''' + b^{-6} P^{(5)} - \ldots\cr R &= - b^{-1} P + b^{-3} P'' - b^{-5} P^{(4)} + \ldots\cr}

-