Solution (source code)

= Solution

Choose a <basis> $\phi_1,\ldots,\phi_N$ of a <conforming finite element space> $V_N\subset H_0^1(0,1)$ and write $y_N=\sum_jc_j\phi_j$. Testing the <variational problem> with each <basis> function gives
$$
\boxed{\sum_{j=1}^N A_{ij}c_j=b_i,\qquad
A_{ij}=\int_0^1(\phi_j'\phi_i'+x\phi_j\phi_i)\,dx,\qquad
b_i=\int_0^1f\phi_i\,dx}.
$$
These are also the equations $\partial J(y_N)/\partial c_i=0$ for the <Ritz method>. The <stiffness matrix> is symmetric and a <positive-definite matrix>: for a nonzero coefficient <vector> $c$, <linear independence> gives $v_N=\sum c_j\phi_j\ne0$, and
$$
c^TAc=a(v_N,v_N)\geq\|v_N'\|_{L^2}^2>0.
$$
Thus there is a unique coefficient <vector>.

Subtracting the exact and discrete <variational problems> proves <Galerkin orthogonality>, $a(y-y_N,v_N)=0$ for every $v_N\in V_N$. In the <energy norm> $\|v\|_a=\sqrt{a(v,v)}$, the <Pythagorean identity> yields
$$
\|y-v_N\|_a^2=\|y-y_N\|_a^2+\|y_N-v_N\|_a^2.
$$
Therefore the <Ritz method> is the best approximation in the <energy norm>. The <Céa lemma> also gives $\|y-y_N\|_V\leq(1+\pi^{-2})\inf_{v_N\in V_N}\|y-v_N\|_V$, so any dense sequence of conforming trial spaces converges.