# Help evaluating an integral expression

I am trying to evaluate what should be a very simple integral but am tripping myself up somewhere and help would be appreciated.

Take the linear hat function $\phi_i(x)$ defined as

$$\phi_i(x)=\begin{cases} (x-x_{i-1})/(x_i-x_{i-1}), & \text{if}\,\, x\in[x_{i-1},x_i] \\ (x_{i+1}-x)/(x_{i+1}-x_{i}), & \text{if}\,\, x\in[x_i,x_{i+1}] \\ 0, & \text{otherwise} \end{cases}$$

over the interval $[0,1]$ divided into $N+1$ intervals of uniform size $h=x_i-x_{i-1}$. Then consider the following:

$$\int_{x_{i-1}}^{x_{i+1}}\phi_i(x)dx=\int_{x_{i-1}}^{x_{i}}\phi_i(x)dx+\int_{x_{i}}^{x_{i+1}}\phi_i(x)dx$$

$$=\int_{x_{i-1}}^{x_{i}}\frac{(x-x_{i-1})}hdx+\int_{x_{i}}^{x_{i+1}}\frac{(x_{i+1}-x)}hdx$$

From here I take the factor of $\frac1h$ out from both integrals and try to evaluate them directly but what I get is something very messy like the following,

$$=\frac1h\left(x_i^2-\frac12(x_{i-1}^2+x_{i+1}^2)+x_{i-1}^2+x_{i+1}^2-x_i(x_{i-1}+x_{i+1})\right)$$

which I know should equal just $h$.

I think I am going about this the wrong way in that their should be a much easier way to evaluate this integral. What am I doing wrong?

• No reason other than not having had the chance to read it yet. Commented Nov 26, 2016 at 20:02
• @Qwerty Lol, stop being so impatient. Commented Nov 26, 2016 at 20:05
• @SimpleArt An hour without any comments or response from the OP, I thought there must be a reason for not accepting! Commented Nov 26, 2016 at 20:06
• @Qwerty There could've been plenty of reasons. For example, he could've been asleep. Many people make posts before they go to bed, waking up roughly 8 hours later and then responding to posts. Commented Nov 26, 2016 at 20:07
• First, the mess you have does equal to $h$. \begin{align} &\frac1h\left(x_i^2-\frac12(x_{i-1}^2+x_{i+1}^2)+x_{i-1}^2+x_{i+1}^2-x_i(x_{i-1}+x_{i+1})\right)\\ = & \frac1h\left(x_i^2+\frac12\left(x_{i-1}^2 + x_{i+1}^2\right)-x_i(x_{i-1}+x_{i+1} \right)\\ = & \frac1h\left(x_i^2+\underbrace{\frac12\left((x_i-h)^2 + (x_i+h)^2\right)}_{x_i^2 + h^2} -2x_i^2\right) = h \end{align} Second, to evaluate the integral, just notice the graph of $\phi_i(x)$ is a triangle of base $2h$ and height $1$. Commented Nov 26, 2016 at 20:15

$$\int_{x_{i-1}}^{x_{i}}\frac{(x-x_{i-1})}hdx+\int_{x_{i}}^{x_{i+1}}\frac{(x_{i+1}-x)}hdx\\={1\over h}\left[\int_{x_{i-1}}^{x_{i}}xdx-x_{i-1}\int_{x_{i-1}}^{x_{i}}dx+x_{i+1}\int_{x_{i}}^{x_{i+1}}dx-\int_{x_{i}}^{x_{i+1}}xdx\right]\\={1\over h}\left({x_i^2-x_{i-1}^2\over 2}-x_{i-1}(x_i-x_{i-1})+x_{i+1}(x_{i+1}-x_i)-{x_{i+1}^2-x_i^2\over 2}\right)\\={1\over h}\left({1\over 2}h(x_i+x_{i-1}) -x_{i-1}h+x_{i+1}h-{1\over 2}h(x_{i+1}+x_i)\right)\\={1\over 2}(x_{i-1}-x_{i+1})+x_{i+1}-x_{i-1}=-h+2h\\=h$$
• I think it should be $\frac{1}{h}\left(\frac{x^2_i-x^2_{i-1}}{2}-x_{i-1}(x_i-x_{i-1})+...\right)$ Commented Nov 26, 2016 at 19:30
• How did you take a factor of $h$ out from $x_i^2-x_{i-1}^2$ and similarly for the last term in the sum between lines three and four of your answer? Commented Nov 26, 2016 at 20:06