# Trouble evaluating an integral expression

Consider the sequence of functions defined as,

$f_n(x)=-1$ if $x\le1-1/n$

and

$f_n(x)=2nx-2n+1$ if $1-1/n\le x\le1$

and evaluate the expression,

$$f_n(x)-\int_0^1f_n(s)ds$$ Now, I know that I should obtain $$f_n(x)-\int_0^1f_n(s)ds=f_n(x)+1-1/n$$ but am unable to do so and don't know what I am doing wrong. Here is what I have done so far: $$f_n(x)-\int_0^1f_n(s)ds=f_n(x)-(\int_0^{1-1/n}f_n(s)ds+\int_{1-1/n}^1f_n(s)ds)$$ $$=f_n(x)-(-\int_0^{1-1/n}ds+\int_{1-1/n}^1(2ns-2n+1)ds$$ $$=f_n(x)+(1-1/n)-\int_{1-1/n}^1f_n(s)ds$$ $$=f_n(x)+1-1/n+n-2/n+1$$

What am I doing wrong?

You made a mistake in the last passage, it should be $$\begin{array}{l} \int_{1 - 1/n}^1 {\left( {2ns - 2n + 1} \right)ds} = \left. {\left( {ns^2 + \left( {1 - 2n} \right)s} \right)\,} \right|_{1 - 1/n}^1 = \\ = \left( {n + \left( {1 - 2n} \right)} \right) - \left( {1 - 1/n} \right)\left( {n\left( {1 - 1/n} \right) + \left( {1 - 2n} \right)} \right) = \\ = \left( {1 - n} \right) - \left( {1 - 1/n} \right)\left( {n - 1 + 1 - 2n} \right) = \\ = \left( {1 - n} \right) + \left( {1 - 1/n} \right)n = \\ = 0 \\ \end{array}$$
$$=f_n(x)-(-\int_0^{1-1/n}ds+\int_{1-1/n}^1(2ns-2n+1)ds=f_n(x)+1-1/n+2n \frac{s^2}{2}\Big|_{1-1/n}^1+(1-2n)s\Big|_{1-1/n}^1$$ $$=f_n(x)+1-1/n+n-n (1-1/n)^2+1-2n-(1-2n)(1-1/n)=f_n(x)+1-1/n\ .$$
{"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}