How to find order of convergence in finite element method computationally when exact solution is unknown for time dependent problem

Say for heat equation or Burgers equation with nonlinear boundary condition. Exact solution is unknown. So I am taking for small mesh size the discrete solution as exact solution. Then how to write the coding part for $L^2$ and $H^1$ error in Matlab?

• Welcome to SciComp.SE. If your question is about how to code something, this might be the wrong place to ask. If not, then I think that you can rephrase your question. Aug 12 '16 at 13:33

If the exact solution is unknown, then yes you have to take the smaller grid as reference. Then you run your simulation with different mesh size, each one varying by a factor 2 and you compute the norm $L^2$ as : $$\vert \vert u-u_{ref}\vert \vert_{L^2} = \sum_{i=1}^n \sqrt{(u(i)-u_{ref}(i))^2}$$ with $n$ the number of grid nodes for the considered mesh. Finally, you plot this quantity in respect to the factor size in a log-log plot and the slope of the curve will give you the order. I can suggest you to look at this NASA website : http://www.grc.nasa.gov/WWW/wind/valid/tutorial/spatconv.html
Don't remember for $H^1$.
An applied mathematician tolds me once that the order of convergence for a specific method is dependent on the choice of the norm, it may be more relevant for a specific case to compute the order with the $L^{\infty}$ norm or the $L^1$ norm or whatever norm you decide to define. If anyone has an expertise here, it would be great to have a detailed explanation.