My solution to $\int \frac{2x^2}{x^2+4}dx$ $$\int \frac{2x^2}{x^2+4}dx$$
Attempt. I have actually done this integral but I'm wondering if what I did was correct as I have a different answer from WolframAlpha. Here it is: $$\int \frac{2x^2}{x^2+4}dx$$
$$2\int \frac{x^2}{x^2+4}dx$$ $$2\int 1dx -2\int\frac{4}{x^2+4}dx$$ $$2x-2\int\frac{4}{x^2+4}dx$$ and here, while I now realise that ther right integral is just $\tan(\frac{x}{2})$, I continued. Let $x=2\tan(\theta)$: $$2x -8\int\frac{1}{4\tan^2(\theta)+4}d\theta$$ $$2x -2\int\frac{1}{\tan^2(\theta)+1}d\theta$$ $$2x -2\int\frac{1}{\sec^2(\theta)}d\theta$$ $$2x -2\int\cos^2(\theta)d\theta$$ $$2x -2\int\frac{\cos(2\theta)+1}{2}d\theta$$ $$2x-\int\cos(2\theta)d\theta-\theta$$ $$2x-\int\cos(2\theta)d\theta-\theta$$ $$2x-\frac12 \sin(2\theta)-\theta$$ $$2x-\frac12 \sin(2\arctan(\frac{x}{2}))-\arctan(\frac{x}{2})$$
Again, I don't really care if there was a shortcut way to this, I just want to know if it is correct or not.
 A: You are trying to integrate a rational function—a quotient of polynomials. If the degree of the numerator is greater than or equal to the degree of the denominator, then use polynomial long division to turn the improper fraction into a proper fraction. This will make life much easier. Here,
$$
\frac{2x^2}{x^2+4}=2-\frac{8}{4+x^2} \, .
$$
Now the problem has been reduced to evaluating
$$
\int\frac{dx}{4+x^2} \, .
$$
We can proceed in the following way:
$$
\int\frac{dx}{4+x^2} = \frac{1}{4}\int\frac{dx}{1+\left(\frac{x}{2}\right)^2} \, .
$$
By the chain rule,
$$
\frac{d}{dx}\left(\arctan\left(\frac{x}{2}\right)\right)=\frac{1}{1+\left(\frac{x}{2}\right)^2}\cdot\frac{1}{2} \tag{*}\label{*} \, ,
$$
and so
$$
\int\frac{dx}{4+x^2}=\frac{1}{4}\int\frac{dx}{1+\left(\frac{x}{2}\right)^2}=\frac{1}{2}\arctan\left(\frac{x}{2}\right)+C \, .
$$
The overall integral therefore equals
$$
\int 2-\frac{8}{4+x^2} \, dx = 2x -4\arctan\left(\frac{x}{2}\right) + C \, .
$$
The substitution you made is perfectly valid, but it is easier to directly apply the chain rule in reverse as I did in $\eqref{*}$. Substitutions should be reserved for more complicated integrals where it is not immediately clear how you can apply the chain rule in reverse.
A: When you went from $\displaystyle-2\int{4\over x^2+4}\,dx$ to $\displaystyle-8\int{1\over4\tan^2(\theta)+4}\,d\theta$ using the substitution $x=2\tan(\theta)$, it looks like you simply replaced $dx$ with $d\theta$. The correct relationship is $dx=2\sec^2(\theta)d\theta$. The secant squared (which cancels the secant squared in the denominator) makes a world of difference.
