.. !split .. _fem:approx:fe:fd: Comparison of finite element and finite difference approximation ================================================================ The previous sections on approximating :math:`f` by a finite element function :math:`u` utilize the projection/Galerkin or least squares approaches to minimize the approximation error. We may, alternatively, use the collocation/interpolation method as described in the section :ref:`fem:approx:fe:impl:ex1:collocation`. Here we shall compare these three approaches with what one does in the finite difference method when representing a given function on a mesh. .. _fem:approx:fe:fd:fdproj: Finite difference approximation of given functions -------------------------------------------------- Approximating a given function :math:`f(x)` on a mesh in a finite difference context will typically just sample :math:`f` at the mesh points. If :math:`u_i` is the value of the approximate :math:`u` at the mesh point :math:`x_{i}`, we have :math:`u_i = f(x_{i})`. The collocation/interpolation method using finite element basis functions gives exactly the same representation, as shown the section :ref:`fem:approx:fe:impl:ex1:collocation`, .. math:: u(x_{i}) = c_i = f(x_{i}){\thinspace .} How does a finite element Galerkin or least squares approximation differ from this straightforward interpolation of :math:`f`? This is the question to be addressed next. We now limit the scope to P1 elements since this is the element type that gives formulas closest to those arising in the finite difference method. .. _fem:approx:fe:fd:feproj: Finite difference interpretation of a finite element approximation ------------------------------------------------------------------ The linear system arising from a Galerkin or least squares approximation reads in general .. math:: \sum_{j\in{\mathcal{I}_s}} c_j ({\psi}_i,{\psi}_j) = (f,{\psi}_i),\quad i\in{\mathcal{I}_s}{\thinspace .} In the finite element approximation we choose :math:`{\psi}_i ={\varphi}_i`. With :math:`{\varphi}_i` corresponding to P1 elements and a uniform mesh of element length :math:`h` we have in the section :ref:`fem:approx:global:linearsystem` calculated the matrix with entries :math:`({\varphi}_i,{\varphi}_j)`. Equation number :math:`i` reads .. _Eq:fem:deq:1D:approx:deq:massmat:diffeq2: .. math:: :label: fem:deq:1D:approx:deq:massmat:diffeq2 \frac{h}{6}(u_{i-1} + 4u_i + u_{i+1}) = (f,{\varphi}_i) {\thinspace .} The first and last equation, corresponding to :math:`i=0` and :math:`i=N` are slightly different, see the section :ref:`fem:approx:fe:A:structure`. The finite difference counterpart to :eq:`fem:deq:1D:approx:deq:massmat:diffeq2` is just :math:`u_i=f_i` as explained in the section :ref:`fem:approx:fe:fd:fdproj`. To easier compare this result to the finite element approach to approximating functions, we can rewrite the left-hand side of :eq:`fem:deq:1D:approx:deq:massmat:diffeq2` as .. math:: h(u_i + \frac{1}{6}(u_{i-1} - 2u_i + u_{i+1})) {\thinspace .} Thinking in terms of finite differences, we can write this expression using finite difference operator notation: .. math:: [h(u + \frac{h^2}{6}D_x D_x u)]_i, which is nothing but the standard discretization of .. math:: h(u + \frac{h^2}{6}u''){\thinspace .} Before interpreting the approximation procedure as solving a differential equation, we need to work out what the right-hand side is in the context of P1 elements. Since :math:`{\varphi}_i` is the linear function that is 1 at :math:`x_{i}` and zero at all other nodes, only the interval :math:`[x_{i-1},x_{i+1}]` contribute to the integral on the right-hand side. This integral is naturally split into two parts according to :ref:`(5.3) `: .. math:: (f,{\varphi}_i) = \int_{x_{i-1}}^{x_{i}} f(x)\frac{1}{h} (x - x_{i-1}) dx + \int_{x_{i}}^{x_{i+1}} f(x)\frac{1}{h}(1 - (x - x_{i})) dx {\thinspace .} However, if :math:`f` is not known we cannot do much else with this expression. It is clear that many values of :math:`f` around :math:`x_{i}` contributes to the right-hand side, not just the single point value :math:`f(x_{i})` as in the finite difference method. To proceed with the right-hand side, we can turn to numerical integration schemes. The Trapezoidal method for :math:`(f,{\varphi}_i)`, based on sampling the integrand :math:`f{\varphi}_i` at the node points :math:`x_{i}=i h` gives .. math:: (f,{\varphi}_i) = \int_\Omega f{\varphi}_i dx\approx h\frac{1}{2}( f(x_{0}){\varphi}_i(x_{0}) + f(x_{N}){\varphi}_i(x_{N})) + h\sum_{j=1}^{N-1} f(x_{j}){\varphi}_i(x_{j}) {\thinspace .} Since :math:`{\varphi}_i` is zero at all these points, except at :math:`x_{i}`, the Trapezoidal rule collapses to one term: .. math:: (f,{\varphi}_i) \approx hf(x_{i}), for :math:`i=1,\ldots,N-1`, which is the same result as with collocation/interpolation, and of course the same result as in the finite difference method. For :math:`i=0` and :math:`i=N` we get contribution from only one element so .. math:: (f,{\varphi}_i) \approx {\frac{1}{2}}hf(x_{i}),\quad i=0,\ i=N {\thinspace .} Simpson's rule with sample points also in the middle of the elements, at :math:`x_{i+\frac{1}{2}}=(x_{i} + x_{i+1})/2`, can be written as .. math:: \int_\Omega g(x)dx \approx \frac{\tilde h}{3}\left( g(x_{0}) + 2\sum_{j=1}^{N-1} g(x_{j}) + 4\sum_{j=0}^{N-1} g(x_{j+\frac{1}{2}}) + f(x_{2N})\right), where :math:`\tilde h= h/2` is the spacing between the sample points. Our integrand is :math:`g=f{\varphi}_i`. For all the node points, :math:`{\varphi}_i(x_{j})=\delta_{ij}`, and therefore :math:`\sum_{j=1}^{N-1} f(x_{j}){\varphi}_i(x_{j})=f(x_{i})`. At the midpoints, :math:`{\varphi}_i(x_{i\pm\frac{1}{2}})=1/2` and :math:`{\varphi}_i(x_{j+\frac{1}{2}})=0` for :math:`j>1` and :math:`j