L2 and H1 Relative Error



Maybe simple question, but I have a problem to find relative error using Matlab.
Firstly, is my consideration true? (shown below)
And
is there any simple or fast solution technique to find L2 and H1 rel. error?

The definition of Relative L2 Error is defined as
(the square root of intergral (ue-ua)^2)/(the square root of integral (ue^2)), and
the definition of Relative H1 Error is defined as
(the square root of intergral (ue-ua)^2+(d/dx(ue-ua))^2+(d/dy(ue-ua))^2)/(the square root of intergral ue^2+(d/dx ue)^2 + (d/dy ue)^2) in 2D,

where 'ue' is the exact solution and 'ua' is the approximate solution.

%The approximated solution is matrix UA
[X,Y]=meshgrid(xmin:dh:xmax,ymin:dh:ymax);
%To find its derivative, I use "gradient" function.
[UAX,UAY]=gradient(UA,dh,dh);
%The exact solution
fun=inline('x.*exp(x+y)','x','y');
funx=inline('(1+x).*exp(x+y)','x','y');
funy=inline('x.*exp(x+y)','x','y');
UE=feval(fun,X,Y);
UEX=feval(funx,X,Y);
UEY=feval(funy,X,Y);
%To find integral I use TRAPZ
l2er=trapz(xmin:dh:xmax,trapz(ymin:dh:ymax,(UE-UA).^2,1),2)/trapz(xmin:dh:xmax,trapz(ymin:dh:ymax,UE.^2,1),2);
h1er=trapz(xmin:dh:xmax,trapz(ymin:dh:ymax,(UE-UA).^2+(UEX-UAX).^2+(UEY-UAY).^2,1),2)/trapz(xmin:dh:xmax,trapz(ymin:dh:ymax,UE.^2+UEX.^2+UEY.^2,1),2);
l2er=sqrt(l2er);h1r=sqrt(h1er);
.



Relevant Pages