Treatment of Constant of Integration for Integration by Parts Question also Requiring Substitution

This post is related to this question. The difference is that, in addition to integration by parts, my problem also requires the use of substitution.

After reading the replies in the aforementioned question, I've decided to write out my problem in full, including the intermediate constants of integration, in order to convince myself that the constants cancel out, leaving a single constant of integration at the end(please see Arturo Magidin's answer to the aforementioned question). However, after doing the calculations, It seems that the inclusion of substitution has made it so that the constants do not cancel, as the answers of the aforementioned question alluded to.

When doing integration by parts, we usually leave out the intermediate constants of integration since they eventually cancel out, and instead we are just left with a single constant of integration at the end. However, when we throw substitution into the mix as well, and after including intermediate constants of integration in the calculation, they do not seem to cancel out so that only one remains at the end.

I'm wondering if this is correct and how I should interpret/understand this phenomenon?

Calculations

$\int x^2e^{2x} \: dx$

Notice how, in addition to using integration by parts, I use substitution in the intermediate steps.

Let $f'(x) = e^{2x}$

$\therefore f(x) = \int e^{2x} \: dx$

Let $u = 2x$

$\implies du = 2dx$

$\implies \dfrac{du}{2} = dx$

$\therefore f(x) = \int \dfrac{e^u}{2} \: du$

$= \dfrac{e^{2x}}{2} + C$

Let $g(x) = x^2$

$\therefore g'(x) = 2x$

$\int x^2e^{2x} \: dx = \left( \dfrac{e^{2x}}{2} + c \right)(x^2) - \int (2x)\left( \dfrac{e^{2x}}{2} + c \right) \: dx$

$\implies \int x^2e^{2x} \: dx = \dfrac{x^2e^{2x}}{2} + cx^2 - \int xe^{2x} + 2xc \: dx$

$\implies \int x^2e^{2x} \: dx = \dfrac{x^2e^{2x}}{2} + cx^2 - \int xe^{2x} \: dx - \int 2xc \: dx$

I now calculate $\int xe^{2x} \: dx$ and $\int 2xc \: dx$ separately and combine them afterwards.

$\int xe^{2x} \: dx$

Let $f'(x) = e^{2x}$

$\therefore f(x) = \int e^{2x} \: dx$

Let $u = 2x$

$\implies du = 2dx$

$\implies \dfrac{du}{2} = dx$

$\therefore f(x) = \int \dfrac{e^u}{2} \: du$

$= \dfrac{e^{2x}}{2} + D$

Let $g(x) = x$

$\therefore g'(x) = 1$

$\int xe^{2x} \: dx = (x)\left( \dfrac{e^{2x}}{2} + D\right) - \int (1)\left(\dfrac{e^{2x}}{2}+ D \right) \: dx$

$= \dfrac{xe^{2x}}{2} + xD - \int \dfrac{e^{2x}}{2} + D \: dx$

Again, let $u = 2x$

$\implies \dfrac{du}{dx} = 2$

$\implies \dfrac{du}{2} = dx$

$= \dfrac{xe^{2x}}{2} + xD - \dfrac{1}{2}\int \dfrac{e^u}{2} + D \: du$

$= \dfrac{xe^{2x}}{2} + xD - \dfrac{e^{2x}}{4} - \dfrac{2}{2}xD$

$\therefore \int xe^{2x} \: dx = \dfrac{xe^{2x}}{2} + xD - \dfrac{e^{2x}}{4} - xD$

Now for the second integral.

$\int 2xc \: dx = 2c \int x \: dx = cx^2 + g$

Nowe we go back to the main integral and substitute the intermediate solutions.

$\int x^2e^{2x} \: dx = \dfrac{x^2e^{2x}}{2} + cx^2 - \int xe^{2x} \: dx - \int 2xc \: dx$

$\implies \int x^2e^{2x} \: dx = \dfrac{x^2e^{2x}}{2} + cx^2 - (\dfrac{xe^{2x}}{2} + xD - \dfrac{e^{2x}}{4} - xD) - (cx^2 + g)$

$\implies \int x^2e^{2x} \: dx = \dfrac{x^2e^{2x}}{2} + cx^2 -\dfrac{xe^{2x}}{2} - xD + \dfrac{e^{2x}}{4} + xD - cx^2 - g$

$\implies \int x^2e^{2x} \: dx = \dfrac{x^2e^{2x}}{2} -\dfrac{xe^{2x}}{2} + \dfrac{e^{2x}}{4} - g$

Notice that at the end, we are still left with many constants of integration ($xc, cu, c$). Based on the answers from the aforementioned question (see Arturo Magidin's answer), I thought that all of the constants would have to cancel out except for one. And this was supposed to show why we didn't need to include intermediate constants of integration when using integration by parts. However, in this case -- the case where I used substitution in addition to integration by parts -- it seems that you DO need to include the constants, since they don't cancel out (subsequently leaving you with a single constant of integration at the end).

Did I do something incorrectly? If not, how should I think about this and/or interpret this for it to make sense?

EDIT

Thanks to Gregory's gracious assistance, I have been able to fix numerous errors in my calculations. As we can now see, all of the constants EXCEPT FOR ONE (g) cancel out, as expected. Therefore, we can conclude that this concept is valid, regardless of whether you use only integration by parts or a combination of integration by parts and substitution.

• I applaud you showing all your work, at the end though you left $u$ when you should probably go back to $u = 2x$. You need to check to make sure you didn't leave out the factors of 2 in places. – Gregory Mar 9 '17 at 18:54
• Also it is good practice to write the different constants of integration as different letters, they don't all need to be the same. You also know that if you have the write answer, then if you differentiate you should get the original equation. Do you? – Gregory Mar 9 '17 at 18:55
• @Gregory Thanks, Greg; I forgot about that one. I also just fixed another error that I found. – The Pointer Mar 9 '17 at 18:55
• Did that fix the error? I assume you know what the correct answer should be. – Gregory Mar 9 '17 at 18:57
• @Gregory I don't think it fixed problem. I will edit my post with my updated results. – The Pointer Mar 9 '17 at 19:18