]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/circulant_inv.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / circulant_inv.m
1 ## Copyright (C) 2012 Nir Krakauer <nkrakauer@ccny.cuny.edu>
2 ##
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## version.
7 ##
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## details.
12 ##
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn{Function File} {@var{c} =} circulant_inv (@var{v})
18 ##
19 ## Fast, compact calculation of inverse of a circulant matrix@*
20 ## Given an @var{n}*1 vector @var{v}, return the inverse @var{c} of the @var{n}*@var{n} circulant matrix @var{C} that has @var{v} as its first column
21 ## The returned @var{c} is the first column of the inverse, which is also circulant -- to get the full matrix, use `circulant_make_matrix(c)'
22 ##
23 ## Theoretically same as @code{inv(make_circulant_matrix(v))(:, 1)}, but requires many fewer computations and does not form matrices explicitly
24 ##
25 ## Roundoff may induce a small imaginary component in @var{c} even if @var{v} is real -- use @code{real(c)} to remedy this
26 ##
27 ## Reference: Robert M. Gray, Toeplitz and Circulant Matrices: A Review, Now Publishers, http://ee.stanford.edu/~gray/toeplitz.pdf, Chapter 3
28 ##
29 ## @seealso{circulant_make_matrix, circulant_matrix_vector_product, circulant_eig}
30 ## @end deftypefn
31
32 function c = circulant_inv(v)
33
34   ## Find the eigenvalues and eigenvectors
35   [vs, lambda] = circulant_eig(v);
36
37   ## Find the first column of the inverse
38   c = vs * diag(1 ./ diag(lambda)) * conj(vs(:, 1));
39
40 endfunction
41
42 %!shared v
43 %! v = [1 2 3]';
44 %!assert (circulant_make_matrix(circulant_inv(v)), inv(circulant_make_matrix(v)), 10*eps);