-
Notifications
You must be signed in to change notification settings - Fork 0
/
diffM.m
45 lines (29 loc) · 862 Bytes
/
diffM.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
% Richard Gooding/Thomas Devries/Jose Lopez
% Forming a differential matrix to perform integration with
%---------------------------------------------------------------
function [D, p] = diffM(n)
%computing chebyshev nodes tau
%computing values at tau nodes for vector 'p'
tau = cos(pi*(0:n)/n);
p = 1./(1 + tau.^2);
% Computing beta weights
beta = ones(size(tau));
for i = 1:n+1
for j = 1:n+1
if i ~= j
beta(j) = beta(j)/(tau(j) - tau(i));
end
end
end
% initializing empty matrix D to be filled
D = zeros(n+1);
% computing entries for D
for i = 1:n+1
for j = 1:n+1
if i ~= j
D(i,j) = beta(j)/((tau(i) - tau(j))*beta(i));
end
end
D(i,i) = -sum(D(i,:));
end
end