-
Notifications
You must be signed in to change notification settings - Fork 22
/
circulant.m
50 lines (40 loc) · 1.13 KB
/
circulant.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
46
47
48
49
50
classdef circulant
properties
vector % Vector of coefficients in first row of matrix.
eig % Vector of eigenvalues.
end
methods
function obj = circulant(c,e)
obj.vector = c;
if nargin < 2, e = length(c)*ifft(c); end
obj.eig = e;
end
function x = plus(a,b)
x = circulant(a.vector + b.vector,a.eig + b.eig);
end
function x = mldivide(a,b)
for j = size(b,2):-1:1 % Reverse order preallocates x.
x(:,j) = fft(a.eig .\ ifft(b(:,j)));
end
end
function x = mtimes(a,b)
n = length(a.vector);
if n ~= length(b.vector)
error('The matrices do not conform for multiplication');
end
e = a.eig.*b.eig; v = fft(e)/n;
x = circulant(v,e);
end
function x = inv(a)
if min(abs(a.eig)) <= eps*max(abs(a.eig))
warning('Matrix is singular to working precision.')
end
n = length(a.vector);
e = 1./a.eig; v = fft(e)/n;
x = circulant(v,e);
end
function disp(a)
disp(a.vector')
end
end
end