0
$\begingroup$

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?

$\endgroup$
7
  • $\begingroup$ No reason other than not having had the chance to read it yet. $\endgroup$ Commented Nov 26, 2016 at 20:02
  • 1
    $\begingroup$ @Qwerty Lol, stop being so impatient. $\endgroup$ Commented Nov 26, 2016 at 20:05
  • $\begingroup$ @SimpleArt An hour without any comments or response from the OP, I thought there must be a reason for not accepting! $\endgroup$
    – Qwerty
    Commented Nov 26, 2016 at 20:06
  • 1
    $\begingroup$ @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. $\endgroup$ Commented Nov 26, 2016 at 20:07
  • 3
    $\begingroup$ 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$. $\endgroup$ Commented Nov 26, 2016 at 20:15

1 Answer 1

0
$\begingroup$

$$\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$$

$\endgroup$
17
  • $\begingroup$ 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)$ $\endgroup$
    – MattG88
    Commented Nov 26, 2016 at 19:30
  • $\begingroup$ @MattG88 Aha ! Thank you very much.. $\endgroup$
    – Qwerty
    Commented Nov 26, 2016 at 19:39
  • $\begingroup$ Not at all!! ;-) $\endgroup$
    – MattG88
    Commented Nov 26, 2016 at 19:40
  • $\begingroup$ 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? $\endgroup$ Commented Nov 26, 2016 at 20:06
  • 1
    $\begingroup$ @Qwerty There is a clear difference between Tryss' comment and here. In the other post, Tryss was providing a constructive comment. You, my friend, were not. Indeed, Tryss makes no assumption that (s)he has the correct answer, nor does (s)he promote his/her answer. Tryss' comment attempts to improve the post, given the clarity of how uncertain you were of the post yourself. The OP, as we see above, seems to be at least somewhat experienced with what (s)he is doing and most likely can make decisions on his/her own. $\endgroup$ Commented Nov 26, 2016 at 20:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .