Home > Src > Level_0 > test.m

test

PURPOSE ^

TEST Script for testing functions of this directory

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

  TEST Script for testing functions of this directory

 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 %  TEST Script for testing functions of this directory
0002 %
0003 % Reference: CHQZ2 = C. Canuto, M.Y. Hussaini, A. Quarteroni, T.A. Zang,
0004 %                    "Spectral Methods. Fundamentals in Single Domains"
0005 %                    Springer Verlag, Berlin Heidelberg New York, 2006.
0006 
0007 %   Written by Paola Gervasio
0008 %   $Date: 2007/04/01$
0009 
0010 
0011 n=5; % polynomial degree
0012 np=n+1; % number of nodes
0013 
0014 % Chebyshev Gauss Lobatto nodes
0015 [x,w]=xwcgl(np);
0016 ww=sum(w);
0017 fig=figure(...
0018 'Name','CGL nodes',...
0019 'Visible', 'on');
0020 plot(x,zeros(np,1),'kx','Markersize',8)
0021 fprintf('CGL: weights sum is %13.6e \n', ww)
0022 
0023 % Lagrange interpolation at CGL nodes
0024 u=sin(x);
0025 x_int=(linspace(-1,1,50))';
0026 a=intlag_cgl(x,x_int);
0027 u_int=a*u;
0028 u1=sin(x_int); 
0029 fig=figure(...
0030 'Name','Lagrange interpolation at CGL nodes',...
0031 'Visible', 'on');
0032 plot(x,u,'ro',x_int,u_int,'b',x_int,u1,'k')
0033 legend('physical unknowns','interpolant','original function')
0034 
0035 
0036 
0037 % first derivative CGL matrix
0038 u=sin(x);
0039 [d]=dercgl(x,np);
0040 u1=d*u;
0041 err=norm(u1-cos(x),inf);
0042 fprintf('CGL: Error on the 1st order pseudospectral derivative %13.6e \n', err)
0043 
0044 % second derivative CGL matrix
0045 u=sin(x);
0046 [d2]=der2cgl(x,np);
0047 u2=d2*u;
0048 err=norm(u2+sin(x),inf);
0049 fprintf('CGL: Error on the 2nd order pseudospectral derivative %13.6e \n', err)
0050 
0051 % Chebyshev Gauss nodes
0052 [x,w]=xwcg(np);
0053 ww=sum(w);
0054 fig=figure(...
0055 'Name','CG nodes',...
0056 'Visible', 'on');
0057 plot(x,zeros(np,1),'kx','Markersize',8)
0058 fprintf('CG: weights sum is %13.6e \n', ww)
0059 
0060 pause
0061 % Legendre Gauss Lobatto nodes
0062 [x,w]=xwlgl(np);
0063 ww=sum(w);
0064 fig=figure(...
0065 'Name','LGL nodes',...
0066 'Visible', 'on');
0067 plot(x,zeros(np,1),'kx','Markersize',8)
0068 fprintf('LGL: weights sum is %13.6e \n', ww)
0069 
0070 % Lagrange interpolation at LGL nodes
0071 u=sin(x);
0072 x_int=(linspace(-1,1,50))';
0073 a=intlag_lgl(x,x_int);
0074 u_int=a*u;
0075 u1=sin(x_int);
0076 fig=figure(...
0077 'Name','Lagrange interpolation at LGL nodes',...
0078 'Visible', 'on');
0079 plot(x,u,'ro',x_int,u_int,'b',x_int,u1,'k')
0080 legend('physical unknowns','interpolant','original function')
0081 
0082 % Lagrange interpolation at LGL nodes (2nd way)
0083 u=sin(x);
0084 x_int=(linspace(-1,1,50))';
0085 [u_int]=legendre_tr_eval(x,u,x_int);
0086 u1=sin(x_int);
0087 fig=figure(...
0088 'Name','Lagrange interpolation at LGL nodesi (2nd)',...
0089 'Visible', 'on');
0090 plot(x,u,'ro',x_int,u_int,'b',x_int,u1,'k')
0091 legend('physical unknowns','interpolant','original function')
0092 
0093 
0094 % first derivative LGL matrix
0095 u=sin(x);
0096 [d]=derlgl(x,np);
0097 u1=d*u;
0098 err=norm(u1-cos(x),inf);
0099 fprintf('LGL: Error on the 1st order pseudospectral derivative %13.6e \n', err)
0100 
0101 % second derivative LGL matrix
0102 u=sin(x);
0103 [d2]=der2lgl(x,np);
0104 u2=d2*u;
0105 err=norm(u2+sin(x),inf);
0106 fprintf('LGL: Error on the 2nd order pseudospectral derivative %13.6e \n', err)
0107 
0108 % Legendre Gauss nodes
0109 [x,w]=xwlg(np);
0110 ww=sum(w);
0111 fig=figure(...
0112 'Name','LG nodes',...
0113 'Visible', 'on');
0114 plot(x,zeros(np,1),'kx','Markersize',8)
0115 fprintf('LG: weights sum is %13.6e \n', ww)
0116 
0117 % first derivative LG matrix
0118 u=sin(x);
0119 [d]=derlg(x,np);
0120 u1=d*u;
0121 err=norm(u1-cos(x),inf);
0122 fprintf('LG: Error on the 1st order pseudospectral derivative %13.6e \n', err)
0123 
0124

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