annotate scripts/linear-algebra/vech.m @ 20170:af2b7695f1c4 draft default tip @

gallery.m: clean and vectorize part of qmult. * scripts/special-matrix/gallery.m: make qmult() follow Octave guidelines, vectorize last for loop in qmult().
author Antonio Pino Robles <data.script93@gmail.com>
date Thu, 28 May 2015 18:32:47 +0200
parents 4197fc428c7d
children 03b9d17a2d95
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 19038
diff changeset
1 ## Copyright (C) 1995-2015 Kurt Hornik
9093
8be05554bbd0 optimize vech
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
2 ## Copyright (C) 2009 VZLU Prague
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
3 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
4 ## This file is part of Octave.
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
5 ##
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
7 ## under the terms of the GNU General Public License as published by
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
9 ## your option) any later version.
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
10 ##
3922
38c61cbf086c [project @ 2002-05-01 06:48:35 by jwe]
jwe
parents: 3458
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
14 ## General Public License for more details.
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
15 ##
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
18 ## <http://www.gnu.org/licenses/>.
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
19
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2745
diff changeset
20 ## -*- texinfo -*-
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2745
diff changeset
21 ## @deftypefn {Function File} {} vech (@var{x})
19038
9e3c35d934ab doc: Periodic spell check of documentation.
Rik <rik@octave.org>
parents: 17744
diff changeset
22 ## Return the vector obtained by eliminating all superdiagonal elements of
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2745
diff changeset
23 ## the square matrix @var{x} and stacking the result one column above the
12639
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
24 ## other. This has uses in matrix calculus where the underlying matrix
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
25 ## is symmetric and it would be pointless to keep values above the main
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
26 ## diagonal.
4d777e05d47c doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents: 11523
diff changeset
27 ## @seealso{vec}
3369
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2745
diff changeset
28 ## @end deftypefn
f37ca3017116 [project @ 1999-11-21 16:26:02 by jwe]
jwe
parents: 2745
diff changeset
29
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
30 ## See Magnus and Neudecker (1988), Matrix differential calculus with
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
31 ## applications in statistics and econometrics.
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
32
5428
2a16423e4aa0 [project @ 2005-08-23 18:38:27 by jwe]
jwe
parents: 5307
diff changeset
33 ## Author KH <Kurt.Hornik@wu-wien.ac.at>
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
34 ## Created: 8 May 1995
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
35 ## Adapted-By: jwe
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
36
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
37 function v = vech (x)
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
38
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
39 if (nargin != 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5428
diff changeset
40 print_usage ();
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
41 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
42
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3922
diff changeset
43 if (! issquare (x))
11472
1740012184f9 Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents: 9093
diff changeset
44 error ("vech: X must be square");
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
45 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3369
diff changeset
46
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
47 n = rows (x);
9093
8be05554bbd0 optimize vech
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
48 slices = cellslices (x(:), (1:n) + n*(0:n-1), n*(1:n));
8be05554bbd0 optimize vech
Jaroslav Hajek <highegg@gmail.com>
parents: 8920
diff changeset
49 v = vertcat (slices{:});
2540
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
50
c3d634d49ce4 [project @ 1996-11-20 00:20:12 by jwe]
jwe
parents:
diff changeset
51 endfunction
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
52
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
53
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
54 %!assert (vech ([1, 2, 3; 4, 5, 6; 7, 8, 9]), [1; 4; 7; 5; 8; 9])
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
55
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
56 %!error vech ()
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
57 %!error vech (1, 2)
7411
83a8781b529d [project @ 2008-01-22 21:52:25 by jwe]
jwe
parents: 7017
diff changeset
58