I am working on a finite element approximation to solve the following ODE type:
$$-\dfrac{d}{dx}\bigg(a(x)\dfrac{du}{dx}\bigg)=f(x)$$
with $u(0) = u(1) = a(0)$, using a Galerkin method. We start by defining a mesh $x_j=jh$ over $N$ points. We take the piecewise function $\phi$ as a basis:
$$\phi_j(x) =\begin{cases} 0&\text{if}\, ~x\not\in(x_{j-1},x_{j+1})\\\\ \dfrac{x-x_{j-1}}{x_{j}-x_{j-1}}&\text{if}\, x\in (x_{j-1},x_{j})\\\\ \dfrac{x_{j+1}-x}{x_{j+1}-x_j}&\text{if}~x\in (x_j,x_{j+1}) \end{cases}$$
Specifically, for the problem:
We take the test method $v(x)=\phi_i(x)$ and the Galerkin method we are using is:
Find $u$ such that $\displaystyle\int_0^1 a(x)\dfrac{du}{dx}\dfrac{dv}{dx}~dx=\displaystyle\int_0^1 f(x)v(x) dx$, for approximation:
$u=\displaystyle\sum_{j=1}^M\xi_j~\phi_j(x)$
Substituting for u and v into the method, the left hand side gives the stiffness matrix with entries
$(a_{ij})=\displaystyle\int_0^1 a(x)\dfrac{d\phi_j}{dx}\dfrac{d\phi_i}{dx}~dx$
In the specific example I'm doing, $a(x)=1$ and we should find:
$(a_{ij})=\begin{cases} \frac{2}{h}&\text{if}\, ~i=j\\ \frac{-1}{h}&\text{if}\, i=j+1,~\text{or}~i=j-1 \end{cases}$
I don't understand how to get those values for $(a_{ij})$?
My attempt:
$$\phi_j'(x) =\begin{cases} 0&\text{if}\, ~x\not\in(x_{j-1},x_{j+1})\\ \dfrac{1}{h}&\text{if}\, x\in (x_{j-1},x_{j})\\ \dfrac{-1}{h}&\text{if}~x\in (x_j,x_{j+1}) \end{cases}$$
But computing $\phi_i'$ seems to be throwing me.
