Solution (source code)

= Solution

Let $\{\phi_j\}_{j=1}^{N-1}$ be the <piecewise-linear hat functions> on a mesh, and put
$$
u_h=\sum_{j=1}^{N-1}U_j\phi_j.
$$
The <Ritz method> requires
$$
\sum_{j=1}^{N-1}K_{ij}U_j=F_i,
\qquad i=1,\ldots,N-1,
$$
where, for $f\equiv1$,
$$
\boxed{
K_{ij}=\int_0^1
\left[(1+x^2)\phi_j'\phi_i'
+x^2\phi_j\phi_i\right]dx,
\qquad
F_i=\int_0^1\phi_i\,dx.
}
$$
Local support makes $K$ symmetric tridiagonal, and coercivity makes it positive definite.