Calculate integral of fractional part I have to calculate $$I=\int _0^1\left\{nx\right\}^2dx , \:\:\:\:\: n \in \mathbb N, n \ge 1$$
Where {a} is $frac(a)$.
I know that $\left\{nx\right\}^2 = (nx - [nx])^2$ so 
$$I\:=\int _0^1\:\left(n^2x^2-2nx\left[nx\right]+\left[nx\right]^2\right)dx=\frac{n^2}{3}-2n\int _0^1\:x\left[nx\right]dx+\int _0^1\:\left[nx\right]^2dx$$ What can I do next ? In my mind, because $x \in [0, 1] \implies [nx] = 0$ but the final answer is $\frac{1}{3}$.
 A: The answer is $1/3$ but not from the reason you mentioned. 
By the substitution $nx=t$, $n dx= dt$, we have
$$
\int_0^1 \{ nx \}^2 dx = \int_0^n \{ t \}^2  \frac1n dt = \frac1n \cdot n \int_0^1 \{t\}^2 dt = \frac13.
$$
A: Other answers have been suggested by now. But we can also do it your way:
We will only have $[nx] = 0$ when $nx < 1$ which happens when $x < 1/n$. However, for $n > 1$, there will be some portion of the integral where $x \ge 1/n$ and so $[nx] = 1$. Likewise, for $n > 2$, there will be some portion where $x \ge 2/n$ and so $[nx]  =2$. In general, we see \begin{align*}\int^1_0 [nx]^2 dx = \sum^n_{k=1} \int_{(k-1)/n}^{k/n} [nx]^2 dx = \sum^n_{k=1} \int^{k/n}_{(k-1)/n} (k-1)^2 dx &= \frac 1 n \sum^n_{k=1} (k-1)^2 \\&=\frac {(n-1)(2n-1)}{6}.\end{align*} Likewise, we see $$\int_0^1x[nx]dx = \sum^n_{k=1} \int^{k/n}_{(k-1)/n} (k-1)x dx = \frac 1 {2n^2} \sum^n_{k=1} (k-1)\left(k^2 - (k-1)^2 \right) = \frac{(n-1)(4n+1)}{12n}.$$ In both of these, I have used the sum of squares formula $\sum_{k=0}^{n-1} k^2 = \frac{(n-1)n(2n-1)}{6}$.  Then we see $$\int^1_0 \{nx \}dx = \frac{n^2}{3} - 2n \frac{(n-1)(4n+1)}{12n} + \frac{(n-1)(2n-1)}{6} = \frac 1 3.$$
A: Fractional part of $ x^2 $ is periodic with period one.and $     frac((nx)^2 )$ is periodic with period $ 1/n$.So the integral can be rewritten as $$\int_0^{n*1/n} frac((nx)^2) dx$$ which is same as $$n\int_0^{1/n} frac((nx)^2) dx$$ in the interval $(0,1/n)$ $ frac((nx)^2) $ is $(nx)^2$ itself.So you could rewrite the integral as $$n\int_0^{1/n} n^2x^2 dx$$ which is easily integrated.
A: $\{nx\}^2$ is a quadratic law $(nx-\lfloor nx\rfloor)^2$, periodically from $k/n$ to $(k+1)/n$, the integral of which is 
$$\int_0^{1/n}n^2x^2\,dx=\frac1{3n}.$$
As there are $n$ such intervals, $$I=\frac13.$$

A: Closed-form antiderivative:
$$(nx-\lfloor nx\rfloor)^2$$
is a piecewise quadratic function. If you integrate from $0$ to $x$, you decompose in $\lfloor nx\rfloor$ complete intervals of width $1/n$ where the integral is easily shown to be $1/3n$, and a final incomplete interval.
Then
$$F(x):=\int_0^x(nt-\lfloor nt\rfloor)^2dt=\frac{\lfloor nx\rfloor}{3n}+\left.\frac{(nt-\lfloor nt\rfloor)^3}{3n}\right|_{t=\lfloor nx\rfloor/n}^x\\
=\color{blue}{\frac{\lfloor nx\rfloor}{3n}+\frac{(nx-\lfloor nx\rfloor)^3}{3n}}.$$

Of course, $F(1)=\dfrac13$.
A: \begin{align}
   \lfloor nx \rfloor = m
   &\iff m \le nx < m+1 \\
   &\iff \dfrac mn \le x < \dfrac{m+1}{n} \\
\end{align}
Let 
\begin{align}
   I_m &= \int_{x=\frac mn}^{\frac{m+1}{n}}\{nx\}^2 dx \\
   &= \int_{x=\frac mn}^{\frac{m+1}{n}}(nx - m)^2 dx
   & \left(\text{Let $y = x - \dfrac mn$.}\right) \\
   &= n^2\int_{y=0}^{\frac 1n}y^2 dy \\
   &= \dfrac{1}{3n} \\
\end{align}
Then
\begin{align}
   I &= \int _0^1\left\{nx\right\}^2dx \\
   &=\sum_{m=0}^{n-1} I_m \\
   &=\dfrac 1n \sum_{m=0}^{n-1} \dfrac 13 \\
   &= \dfrac 13
\end{align}
