Borrar filtros
Borrar filtros

Chebyshev Differentiation Matrix without using function 'cheb'

5 visualizaciones (últimos 30 días)
Alpha Lee
Alpha Lee el 3 de Dic. de 2020
Respondida: Sufiyan el 30 de Mzo. de 2023
May I ask if there is any way to create a Chebyshev Differentiation Matrix code without using 'cheb' ?

Respuestas (1)

Sufiyan
Sufiyan el 30 de Mzo. de 2023
Hi,
You can refer to the code below.
% Set up the domain
N = 10; % Number of points in the domain
x = cos(pi*(0:N-1)/(N-1))'; % Chebyshev nodes
% Compute the differentiation matrix
D = zeros(N);
for k=1:N
for j=1:N
if k~=j
D(k,j) = ((-1)^(k+j))/(x(k)-x(j));
end
end
end
D = D - diag(sum(D,2)); % Set the diagonal elements
% Test the differentiation matrix
f = @(x) sin(5*x);
df_true = @(x) 5*cos(5*x);
df_approx = D*f(x);
error = norm(df_true(x) - df_approx,inf);
fprintf('Error: %e\n',error);

Categorías

Más información sobre Programming en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by