]> Creatis software - CreaPhase.git/blob - octave_packages/linear-algebra-2.2.0/circulant_make_matrix.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / linear-algebra-2.2.0 / circulant_make_matrix.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_make_matrix (@var{v})
18 ##
19 ## Produce a full circulant matrix given the first column@*
20 ## Given an @var{n}*1 vector @var{v}, returns the @var{n}*@var{n} circulant matrix @var{C} where @var{v} is the left column and all other columns are downshifted versions of @var{v}
21 ##
22 ## Note: If the first row @var{r} of a circulant matrix is given, the first column @var{v} can be obtained as @code{v = r([1 end:-1:2])}
23 ##
24 ## Reference: Gene H. Golub and Charles F. Van Loan, Matrix Computations, 3rd Ed., Section 4.7.7
25 ##
26 ## @seealso{circulant_matrix_vector_product, circulant_eig, circulant_inv}
27 ## @end deftypefn
28
29 function C = circulant_make_matrix(v)
30
31   n = numel(v);
32   C = ones(n, n);
33   for i = 1:n
34     C(:, i) = v([(end-i+2):end 1:(end-i+1)]); #or circshift(v, i-1)
35   endfor
36
37 endfunction
38
39 %!shared v,C
40 %! v = [1 2 3]'; C = [1 3 2; 2 1 3; 3 2 1];
41 %!assert (circulant_make_matrix(v), C);