# What can I do to calculate the L2 norm between the exact solution and my numerical solution?

**URL:** <https://discourse.julialang.org/t/what-can-i-do-to-calculate-the-l2-norm-between-the-exact-solution-and-my-numerical-solution/114359>\
**Category:** Numerics\
**Tags:** question, fem, diferential-equation\
**Created:** [May 16, 2024, 1:47pm UTC](https://discourse.julialang.org/t/what-can-i-do-to-calculate-the-l2-norm-between-the-exact-solution-and-my-numerical-solution/114359 "2024-05-16T13:47:13Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [May 16, 2024, 2:23pm UTC](https://discourse.julialang.org/t/what-can-i-do-to-calculate-the-l2-norm-between-the-exact-solution-and-my-numerical-solution/114359/4 "2024-05-16T14:23:52Z")

</div>

An example is given [at the end of this tutorial](https://gridap.github.io/Tutorials/dev/pages/t012_emscatter/#Compare-the-difference-in-the-%22center%22-region-1).

I think you need something like `sum(abs2(T - uₕ) * dΩ)`, though in the tutorial it first projects the analytical solution into the FEM basis. In general, if you want to compose an arbitrary function `f` with a cell field `u`, you need to use `f ∘ u`, e.g. `(x -> x^2) ∘ uₕ`. But a specialized `CellField` method is [already defined](https://github.com/gridap/Gridap.jl/blob/9079dd1ac56da9ca5f6d8d3952d69caa6c014fa4/src/CellData/CellFields.jl#L619-L623) for [`abs2`](https://docs.julialang.org/en/v1/base/math/#Base.abs2).

---

_[View the full topic](https://discourse.julialang.org/t/what-can-i-do-to-calculate-the-l2-norm-between-the-exact-solution-and-my-numerical-solution/114359)._
