Home > Src > Level_1 > errors_1d.m

errors_1d

PURPOSE ^

ERRORS_1D Computes errors for 1D b.v.p.

SYNOPSIS ^

function [err_inf,err_h1,err_l2]=errors_1d(nx,ne,xa,xb,un,uex,uexx,param);

DESCRIPTION ^

 ERRORS_1D Computes errors  for 1D b.v.p.

 Input: 
      nx = polynomial degree in each element (the same in each element)
             to be set only if p=4, otherwise, nx=p;
      ne = number of elements (equally spaced)
      xa, xb = extrema of computational domain Omega=(xa,xb)
      un = numerical solution produced, e.g., by lap_1d, ellprecofem_1d,..
      uex  = exact solution (uex=@(x)[uex(x)], with .*, .^, ./)
      uexx = first derivative of exact solution (uexx=@(x)[uexx(x)], 
             with .*, .^, ./)
      param(1) = 1: compute errors (L^inf-norm, L2-norm, H1-norm)
                      on the exact solution
                 2: no  errors are computed
      param(2) = 0: LG quadrature formulas with high precision degree are
                      used to compute norms (exact norms)
                 1: LGL quadrature formulas with npdx,npdy nodes are
                      used to compute norms (discrete norms)
                   (used only if param(1) == 1)
      param(3) = number of nodes for high degree quadrature formula,
                   (used only if param(2) == 0 & param(1) == 1)
      param(4) = 0: absolute errors are computed
                 1: relative errors are computed
                   (used only if param(1) == 1)

 Output: 
         err_inf = ||u_ex-u_N|| with respect to discrete maximum-norm
         err_h1 = ||u_ex-u_N|| with respect to discrete H1-norm
         err_l2 = ||u_ex-u_N|| with respect to discrete L2-norm

 Reference: CHQZ2 = C. Canuto, M.Y. Hussaini, A. Quarteroni, T.A. Zang,
                    "Spectral Methods. Fundamentals in Single Domains"
                    Springer Verlag, Berlin Heidelberg New York, 2006.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [err_inf,err_h1,err_l2]=errors_1d(nx,ne,xa,xb,un,uex,uexx,param);
0002 % ERRORS_1D Computes errors  for 1D b.v.p.
0003 %
0004 % Input:
0005 %      nx = polynomial degree in each element (the same in each element)
0006 %             to be set only if p=4, otherwise, nx=p;
0007 %      ne = number of elements (equally spaced)
0008 %      xa, xb = extrema of computational domain Omega=(xa,xb)
0009 %      un = numerical solution produced, e.g., by lap_1d, ellprecofem_1d,..
0010 %      uex  = exact solution (uex=@(x)[uex(x)], with .*, .^, ./)
0011 %      uexx = first derivative of exact solution (uexx=@(x)[uexx(x)],
0012 %             with .*, .^, ./)
0013 %      param(1) = 1: compute errors (L^inf-norm, L2-norm, H1-norm)
0014 %                      on the exact solution
0015 %                 2: no  errors are computed
0016 %      param(2) = 0: LG quadrature formulas with high precision degree are
0017 %                      used to compute norms (exact norms)
0018 %                 1: LGL quadrature formulas with npdx,npdy nodes are
0019 %                      used to compute norms (discrete norms)
0020 %                   (used only if param(1) == 1)
0021 %      param(3) = number of nodes for high degree quadrature formula,
0022 %                   (used only if param(2) == 0 & param(1) == 1)
0023 %      param(4) = 0: absolute errors are computed
0024 %                 1: relative errors are computed
0025 %                   (used only if param(1) == 1)
0026 %
0027 % Output:
0028 %         err_inf = ||u_ex-u_N|| with respect to discrete maximum-norm
0029 %         err_h1 = ||u_ex-u_N|| with respect to discrete H1-norm
0030 %         err_l2 = ||u_ex-u_N|| with respect to discrete L2-norm
0031 %
0032 % Reference: CHQZ2 = C. Canuto, M.Y. Hussaini, A. Quarteroni, T.A. Zang,
0033 %                    "Spectral Methods. Fundamentals in Single Domains"
0034 %                    Springer Verlag, Berlin Heidelberg New York, 2006.
0035 
0036 %   Written by Paola Gervasio
0037 %   $Date: 2007/04/01$
0038 
0039 npdx=nx+1;
0040 
0041 [x,wx]=xwlgl(npdx); dx=derlgl(x,npdx);
0042 
0043 % nov
0044 ldnov=npdx; nov=zeros(ldnov,ne);
0045 [nov]=cosnov_1d(npdx,ne,nov);
0046 noe=nov(npdx,ne);
0047 
0048 % Uniform decomposition of  Omega in ne elements
0049 [xx,jacx,xy,ww]=mesh_1d(xa,xb,ne,npdx,nov,x,wx);
0050 
0051 if(param(1)==1)
0052 % Evaluate exact solution to compute errors
0053 nq=param(3); fdq=param(2); err_type=param(4);
0054 
0055 u=uex(xy);
0056 
0057 %
0058 
0059 err=u-un;
0060 
0061 % ||u_ex-u_N|| with respect to discrete maximum-norm
0062 
0063 if err_type==0
0064 err_inf=norm(err,inf);
0065 else
0066 err_inf=norm(err,inf)/norm(u,inf);
0067 end    
0068 
0069 
0070 % ||u_ex-u_N|| with respect to H1 norm
0071 % fdq=0 LG quadrature formula with nq nodes in each element
0072 % fdq=1 LGL quadrature formula with npdx nodes in each element
0073 [err_h1]=normah1_1d(fdq, nq, err_type, un, uex, uexx,...
0074  x, wx, dx, xx, jacx, xy,nov);
0075 
0076 % ||u_ex-u_N|| with respect to L2 norm
0077 
0078 [err_l2]=normal2_1d(fdq, nq, err_type, un, uex, ...
0079  x, wx, xx, jacx, xy,nov);
0080 end
0081 
0082 return

Generated on Fri 21-Sep-2007 10:07:00 by m2html © 2003