# How to calculate an average error between numerical and analytical solution of the PDE?

I have second-order initial boundary value problem. Here's my code returning numerical solution (and plotting it).

solution =
NDSolve[{D[u[t, x, y], t] ==
D[u[t, x, y], x, x] + D[u[t, x, y], y, y] - x * y * Sin[t],
u[t, 0, y] == 0, u[t, 1, y] == Derivative[0, 1, 0][u][t, 1, y],
u[t, x, 0] == 0, u[t, x, 1] == Derivative[0, 0, 1][u][t, x, 1],
u[0, x, y] == x*y}, u, {t, 0, 6}, {x, 0, 1}, {y, 0, 1},
Method -> {"MethodOfLines",
"SpatialDiscretization" -> {"TensorProductGrid",
"DifferenceOrder" -> "Pseudospectral"}}]
Plot3D[First[u[6, x, y] /. solution], {x, 0, 1}, {y, 0, 1},
PlotRange -> All, PlotPoints -> 40]


In addition, I have analytical solution (just plotting it) [here is Cos[t], t = 6] :

Plot3D[x * y * Cos[6], {x, 0, 1}, {y, 0, 1}, PlotRange -> All,
PlotPoints -> 40]


The question is how to find an average error (difference) between analytical and numerical solutions with specified time T? Thank you.

It depends on your exact definition of "average error", but for example:

NIntegrate[Abs@(First[u[6, x, y] /. solution] - (x*y*Cos[6])), {x, 0, 1}, {y, 0, 1},
AccuracyGoal -> 5]
(* 0.0250133 *)

• I guess, that's the answer. Thank you! Nov 18, 2015 at 19:30
• @instajke This is the $L^1$ norm; in general, there is the $L^p$ norm Nov 18, 2015 at 23:28
• @MichaelE2 Also you may want absolute or relative errors, etc. People tend to think of errors in convoluted ways ... Nov 18, 2015 at 23:38