Example 6.12
Calculation of Derivatives Using Chebyshev Derivative Matrix Operator
Contents
Initialization
close all; clear N u j X U D j k N = 5; u = @(x) 4*x.^2.*(1-x.^2).*exp(-x/2); j = [0:N]'; X = cos(j*pi/N); U = u(X); D = zeros(N+1,N+1);
Creation of the matrix operator
for j = [1:N+1] for k = [1:N+1] if j==k switch j case 1 D(j,k) = (2*N^2+1)/6; case N+1 D(j,k) = -(2*N^2+1)/6; otherwise D(j,k) = -X(j)/(2*(1-X(j)^2)); end; else if or(j==1,j==N+1) cj = 2; else cj = 1; end; if or(k==1,k==N+1) ck = 2; else ck = 1; end; D(j,k) = cj*(-1)^(j+k)/(ck*(X(j)-X(k))); end; end; end;
Display the results
X U D D*U
X =
1.000000000000000
0.809016994374947
0.309016994374947
-0.309016994374947
-0.809016994374947
-1.000000000000000
U =
0
0.603582782590411
0.296029630345352
0.403217672421526
1.355465472313722
0
D =
Columns 1 through 5
8.500000000000000 -10.472135954999581 2.894427190999916 -1.527864045000421 1.105572809000084
2.618033988749895 -1.170820393249937 -2.000000000000000 0.894427190999916 -0.618033988749895
-0.723606797749979 2.000000000000000 -0.170820393249937 -1.618033988749895 0.894427190999916
0.381966011250105 -0.894427190999916 1.618033988749895 0.170820393249937 -2.000000000000000
-0.276393202250021 0.618033988749895 -0.894427190999916 2.000000000000000 1.170820393249936
0.500000000000000 -1.105572809000084 1.527864045000421 -2.894427190999916 10.472135954999574
Column 6
-0.500000000000000
0.276393202250021
-0.381966011250105
0.723606797749979
-2.618033988749894
-8.500000000000000
ans =
-4.581460762243603
-1.775821173923400
1.716542943367882
-2.702927992451481
2.501699686116691
12.812522829475302