3
$\begingroup$

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.

$\endgroup$

1 Answer 1

3
$\begingroup$

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 *)
$\endgroup$
3
  • $\begingroup$ I guess, that's the answer. Thank you! $\endgroup$
    – instajke
    Nov 18, 2015 at 19:30
  • 2
    $\begingroup$ @instajke This is the $L^1$ norm; in general, there is the $L^p$ norm $\endgroup$
    – Michael E2
    Nov 18, 2015 at 23:28
  • 1
    $\begingroup$ @MichaelE2 Also you may want absolute or relative errors, etc. People tend to think of errors in convoluted ways ... $\endgroup$ Nov 18, 2015 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.