.. !split .. _fem:deq:1D:fem1: Computing with finite elements ============================== The purpose of this section is to demonstrate in detail how the finite element method can the be applied to the model problem .. math:: -u''(x) = 2,\quad x\in (0,L),\ u(0)=u(L)=0, with variational formulation .. math:: (u',v') = (2,v)\quad\forall v\in V{\thinspace .} The variational formulation is derived in the section :ref:`fem:deq:1D:varform`. Finite element mesh and basis functions --------------------------------------- We introduce a finite element mesh with :math:`N_e` cells, all with length :math:`h`, and number the cells from left to right. global nodes. Choosing P1 elements, there are two nodes per cell, and the coordinates of the nodes become .. math:: x_{i} = i h,\quad h=L/N_e,\quad i=0,\ldots,N_n=N_e+1, provided we number the nodes from left to right. Each of the nodes, :math:`i`, is associated a finite element basis function :math:`{\varphi}_i(x)`. When approximating a given function :math:`f` by a finite element function :math:`u`, we expand :math:`u` using finite element basis functions associated with *all* nodes in the mesh, i.e., :math:`N=N_n`. However, when solving differential equations we will often have :math:`N