---
# System prepended metadata

title: 11-1. Chebyshev points of the first kind
tags: [Final reports]

---

---
title: 11-1. Chebyshev points of the first kind
tags: Final reports
---

**Reference**
1. The Chebyshev points of the first kind, Kuan Xu, Applied Numerical Mathematics 102 (2016) 17–30, . [10.1016/j.apnum.2015.12.002](https://doi.org/10.1016/j.apnum.2015.12.002)

---

## Questions to be answered

1. How to obtain Chebyshev coefficients from points, and inversely, points from coefficients. 

2. how to perform interpolation, differentiation and integration

3. How to solve two-point boundary value problems

4. How to transform between 1st kind and 2nd kind points?

---
(閔中)
## 1 
![](https://i.imgur.com/q8xdVsw.png)
![](https://i.imgur.com/LZagn3f.png)
![](https://i.imgur.com/I3pmwQ5.png)
![](https://i.imgur.com/bAjoAr0.png)
![](https://i.imgur.com/fXhJs8A.png)
![](https://i.imgur.com/IqfEmJS.png)
![](https://i.imgur.com/fMiwTMg.png)
![](https://i.imgur.com/jqf9aG0.png)
![](https://i.imgur.com/WkNkGhD.png)
```
clc
clear

n  = 100;
k  = (0:n-1)';
thetak = (2*k+1)*pi/(2*n);
xk     = cos(thetak);
f  = xk.^10;

c  = zeros(n,n);
for i = 1:n
    for j = 1:n
    c(i,j) =  cos((i-1)*thetak(j));   
    end
end
c(1,:) = 0.5*c(1,:);
C      = 2/n*c;

cn     = C*f;
semilogy(abs(cn))

Cinv =  zeros(n,n);
for i = 1:n
    for j = 1:n
    Cinv(i,j) =  cos((j-1)*thetak(i));   
    end
end

finv = Cinv*cn;

figure(1)
subplot(2,1,1)
semilogy(cn,'ro'); hold on
xlabel('j') 
ylabel('cj')
subplot(2,1,2)
plot(xk,finv,'ro'); hold on
plot(xk,f,'b'); hold off
xlabel('x') 
ylabel('f')
legend('Cc','f(xk1)')
```

## 2
![](https://i.imgur.com/gqPUCG7.png)
![](https://i.imgur.com/5qPGMFT.png)
![](https://i.imgur.com/HoIKIro.png)

```
clc
clear

n  = 100;
k  = (0:n-1)';
thetak = (2*k+1)*pi/(2*n);
xk     = cos(thetak);

f  = sin(xk);

xj = (-1:0.01:1)';
m  = length(xj);

a = zeros(m,m);
for j = 1:m
a(j,j) = 1/sum((-1).^(0:n-1)'.*sin(thetak)./(xj(j)-xk));
end

A = zeros(m,n);
for j = 1:n
    for i = 1:m
    A(i,j) = (-1)^(j-1)*sin(thetak(j))/(xj(i)-xk(j)); 
    end
end

P = a*A*f;

error = abs(P-sin(xj));


figure(1)
subplot(2,1,1)
plot(xk,f,'ro'); hold on;
plot(xj,P,'b'); hold off;
xlabel('x') 
ylabel('f')
legend('Pf(x)','f(xk1)')
subplot(2,1,2)
semilogy(xj,error);
xlabel('x') 
ylabel('|Pf(x)-f(xk1)|')
```

![](https://i.imgur.com/3jtOuCG.png)
![](https://i.imgur.com/xsWC3vO.png)
![](https://i.imgur.com/wS5vTPF.png)

```
clc
clear

n  = 100;
k  = (0:n-1)';
thetak = (2*k+1)*pi/(2*n);
xk     = cos(thetak);

f  = sin(xk);

dTn = n*sin(n*thetak)./sin(thetak);

D   = zeros(n,n);

for i = 1:n
   for j = 1:n
   if j == i
   D(i,i) = xk(i)/(2*(1-xk(i)^2));
   else
   D(i,j) = dTn(i)/((xk(i)-xk(j))*dTn(j));    
   end
   end
end

df = D*f;
error = abs(df-cos(xk));

figure(1)
subplot(2,1,1)
plot(xk,cos(xk)); hold on;
plot(xk,df,'ro'); hold off;
xlabel('x') 
ylabel('df/dx')
legend('Df(xk1)','df/dx')
subplot(2,1,2)
semilogy(xk,error);
xlabel('x') 
ylabel('|Df(xk1)-df/dx|')
```

![](https://i.imgur.com/5RHJ7EH.png)

```
clc
clear

n  = 100;
k  = (0:n-1)';
thetak = (2*k+1)*pi/(2*n);
xk     = cos(thetak);

f  = cos(xk);

wk = zeros(n,1);
for i = 1:n
wk(i) = 2/n*(1-2*sum( cos(2*(1:fix(n/2))*thetak(i))./(4*(1:fix(n/2)).^2-1)) );
end

In = wk'*f;
In_exact = 2*sin(1);
error = In_exact-In;
disp(In)
disp(error)
```

## 3

![](https://i.imgur.com/4hTn53W.png)
![](https://i.imgur.com/NMxNUfV.png)
![](https://i.imgur.com/18OAj9N.png)
![](https://i.imgur.com/X89adaO.png)
![](https://i.imgur.com/32jZRQi.png)

```
clc
clear

%=================2nd kind to 1st kind==============
n  = 1000;
k1  = (0:n-3)';
k2  = (0:n-1)';
thetak_1 = (2*k1+1)*pi/(2*(n-2));
thetak_2 = k2*pi/(n-1);

xk_1     = cos(thetak_1);
xk_2     = cos(thetak_2);

f  = xk_2.^2;

m  = length(xk_1);

plus = [0.5;ones(n-2,1);0.5];
a = zeros(m,m);
for j = 1:m
a(j,j) = 1/sum(plus.*(-1).^(0:n-1)'./(xk_1(j)-xk_2));
end
A = zeros(m,n);
for j = 1:n
    for i = 1:m
    A(i,j) = plus(j)*(-1)^(j-1)/(xk_1(i)-xk_2(j)); 
    end
end
P = a*A;
%=============================================

%=================D^2 of 2nd kind==============
D2   = zeros(n,n);
ci(1)   = 2;
ci(n)   = 2;
ci(2:n-1) = 1;
for i = 1:n
   for j = 1:n
       
   if j == i
       if j == 1
       D2(i,i) = (2*(n-1)^2+1)/6;
       elseif j == n
       D2(i,i) = -(2*(n-1)^2+1)/6;    
       else
       D2(i,i) = -xk_2(i)/(2*(1-xk_2(i)^2));
       end
   else
       D2(i,j) = ci(i)/ci(j) * (-1)^(i+j-2)/(xk_2(i)-xk_2(j));
   end
   
   end
end
%=============================================

%=================BC==========================
LBC = [zeros(1,n-1) 1];
RBC = [1 zeros(1,n-1)];

D1D1 = [P*D2^2;LBC;RBC];
f1   = [P*f;0;0];
%=============================================

u = D1D1\f1;
u = u(2:end-1);

u_exact = 1/12*xk_1.^4-1/12;

error = abs(u_exact-u);

figure(1)
subplot(2,1,1)
plot(xk_1,u,'ro'); hold on;
plot(xk_1,u_exact,'b'); hold off;
xlabel('x') 
ylabel('u')
legend('numerical','exact')
subplot(2,1,2)
semilogy(xk_1,error);
xlabel('x') 
ylabel('|u-uexact')

```

## 4

![](https://i.imgur.com/xg8eq6u.png)

```
clc
clear

%=================2nd kind to 1st kind==============
n  = 1000;
k1  = (0:n-3)';
k2  = (0:n-1)';
thetak_1 = (2*k1+1)*pi/(2*(n-2));
thetak_2 = k2*pi/(n-1);

xk_1     = cos(thetak_1);
xk_2     = cos(thetak_2);

f  = xk_2.^2;

m  = length(xk_1);

plus = [0.5;ones(n-2,1);0.5];
a = zeros(m,m);
for j = 1:m
a(j,j) = 1/sum(plus.*(-1).^(0:n-1)'./(xk_1(j)-xk_2));
end
A = zeros(m,n);
for j = 1:n
    for i = 1:m
    A(i,j) = plus(j)*(-1)^(j-1)/(xk_1(i)-xk_2(j)); 
    end
end
P = a*A;
%=============================================

f_xk1_p = P*f;
f_xk1   = xk_1.^2;

error = abs(f_xk1_p-f_xk1);

figure(1)
subplot(2,1,1)
plot(xk_1,f_xk1_p,'ro'); hold on;
plot(xk_1,f_xk1,'b'); hold off;
xlabel('x') 
ylabel('f')
legend('Pf(xk2)','f(xk1)')
subplot(2,1,2)
semilogy(xk_1,error);
xlabel('x') 
ylabel('|f(xk1)-Pf(xk2)|')
```