What is $\int|x^n|dx$? I need to solve $$\int|x^n| \, dx$$ if n is an odd positive integer.
I think it should be $\dfrac{|x|^{n+1}}{n+1}+c$, but this is wrong. I am new to integration so I don’t know what to do when there is modulus function.
The answer given at back of book is $\dfrac{|x^n|x}{n+1} +c$.
If $x$ is real or complex isn’t mentioned.
 A: HINT: you can rewrite the indefinite integral as
$$\int |x^n|\mathrm dx=\int |x|^n\mathrm dx=\int(\operatorname{sign}(x))^nx^n\mathrm dx=\int\operatorname{sign}(x^n)x^n\mathrm dx,\quad n\in\Bbb N_{>0}\tag1$$
where
$$\operatorname{sign}(x):=\begin{cases}1,&x> 0\\-1,&x<0\\0,&x=0\end{cases}\tag2$$
and
$$\frac{\mathrm d}{\mathrm dx}\operatorname{sign}(x^n)=0,\quad\text{for } n\in\Bbb N_{>0}\,\text{ and whenever } x\neq 0\tag3$$
Then applying integration by parts in $(1)$ we finally get
$$\int |x|^n\mathrm dx=\operatorname{sign}(x^n)\frac{x^{n+1}}{n+1}+C\tag4$$
what is almost an indefinite integral in the general accepted convention, that is, the RHS is almost an antiderivative of the integrand because 
$$\left[\operatorname{sign}(x^n)\frac{x^{n+1}}{n+1}+C\right]'=|x|^n,\quad\text{whenever }x\neq 0\tag5$$
If $n>1$ is odd then we have that $\operatorname{sign}(x^n)x^{n+1}=x|x^n|$. Also note that I used the identity $|x^n|=|x|^n$, for $n\in\Bbb N_{>0}$. Thus for odd $n>1$ the result on $(4)$ becomes an indefinite integral in the general convention.
A: Assuming $x$ is a real number and $n$ is odd, we have $$
|x|^n = \begin{cases}
x^n & \text{if}\ x\geq 0, \\
-x^n & \text{if}\ x<0.
\end{cases}$$
Use this to remove the modulus. That is, the antiderivative will be different depending on whether $x$ is positive or negative. For example, the antiderivative of $|x|$ is
$$
\begin{cases}
\frac{1}{2}x^2+C & \text{if}\ x>0, \\
-\frac{1}{2}x^2+C & \text{if}\ x<0.
\end{cases}
$$
What about at $x=0$?
A: Short answer:
$|x^n|$ is an even function so that its antiderivative must be odd (to a constant), i.e. have the sign of $x$. This explains
$$\frac{|x^n|x}{n+1}.$$
