0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 n=5;
0012 np=n+1;
0013
0014
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
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
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
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
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
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
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
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
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
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
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
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