function [L2err,H01err,ENerr] = solerr(elements3,coordinates,u)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% solerr: template for computing error on triangular elements
%% works with ACF code (Alberty/Carstensen/Funken)
%% MPeszynska, for MTH 655-9, Winter 2017
%% Mathematics, Oregon State University
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Remarks: 
%% This function should be called from fem2d.m or fem2d*.m 
%% User must provide the function exact()
%% Functions tri_quadcofs and basisfun must be available
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

L2err=0;
H01err=0;
ENerr=0;

for j = 1:size(elements3,1)

  [wq,xq,yq]= tri_quadcofs(coordinates(elements3(j,:),:),1);

  %%%%%%%%%%%%%%%%%%%%%% compute the actual integral of uex,unum
  ord = size(wq,2);
  quadv = 0;

  for k=1:ord 

    [vnum,dnum] = basisfun (xq(k),yq(k),...
           coordinates(elements3(j,:),:),u([elements3(j,:)]));
    [vex,dex] = exact([xq(k),yq(k)]);
    v   = vnum - vex;

    quadv = quadv + wq(i)*v*v;

  end
  %%%%%%%%%%%%%%%%%%%%
  L2err = L2err + quadv;

end

L2err = sqrt(L2err);

