Error

PURPOSE ^

function that calculates three different errors

SYNOPSIS ^

function [L2err,H1err,LI0err] = Error(ue,xp,uh)

DESCRIPTION ^

 function that calculates three different errors
 the discrete L2error, the discrete H1error and the L_inf error

 input:   o ue.......the exact solution as function_handle
          o xp.......vector containing the gridpoints
          o uh.......vector containing the numerical solution

 output:  o L2err....error calculated in discrete L2 norm
          o H1err....error calculated in discrete H1 norm
          o LI0err...error calculated in L_inf norm

 notes:   o for big step sizes the approximated derivation could not fit
            to the exact one and the H1err could get to big
          o might be buggy, please mail if you have an improvement...

 authors: o Christian Jäkel (University of Technology Dresden)
          o Daniel Klawitter (University of Technology Dresden)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [L2err,H1err,LI0err] = Error(ue,xp,uh)
0002 % function that calculates three different errors
0003 % the discrete L2error, the discrete H1error and the L_inf error
0004 %
0005 % input:   o ue.......the exact solution as function_handle
0006 %          o xp.......vector containing the gridpoints
0007 %          o uh.......vector containing the numerical solution
0008 %
0009 % output:  o L2err....error calculated in discrete L2 norm
0010 %          o H1err....error calculated in discrete H1 norm
0011 %          o LI0err...error calculated in L_inf norm
0012 %
0013 % notes:   o for big step sizes the approximated derivation could not fit
0014 %            to the exact one and the H1err could get to big
0015 %          o might be buggy, please mail if you have an improvement...
0016 %
0017 % authors: o Christian Jäkel (University of Technology Dresden)
0018 %          o Daniel Klawitter (University of Technology Dresden)
0019 
0020 
0021 % for H1err we need the derivation of the exact solution
0022 uprime = str2func(['@(x)',char(diff(sym(ue)))]);
0023 
0024 % set the errors to zero, for summation
0025 L2err = 0;
0026 H1err = 0;
0027 
0028 
0029 h = diff(xp);
0030 duh = diff(uh)./h;
0031 for j = 1:length(uh)
0032     %         L2err = L2err + sqrt(h(j))*(ue(xp(j))-uh(j))^2;
0033     L2err = L2err + (ue(xp(j))-uh(j))^2;
0034 end
0035 for j = 1:length(duh)
0036     %L2err = L2err + (ue(xp(j))-uh(j))^2;
0037     H1err = H1err + ((uprime(xp(j)))-duh(j))^2;
0038 end
0039 
0040 H1err = sqrt(mean(h))*sqrt(H1err + L2err);
0041 L2err = sqrt(mean(h))*sqrt(L2err);
0042 
0043     
0044 
0045 
0046 
0047 for k = 1:length(xp)
0048     uex(k) = ue(xp(k));
0049 end
0050 
0051 LI0err = max(abs(uex-uh));

Generated on Wed 01-Jul-2009 16:09:39 by m2html © 2003