Mercurial > octave
annotate scripts/linear-algebra/vech.m @ 23220:092078913d54
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 22 Feb 2017 12:58:07 -0500 |
parents | ef4d915df748 3ac9f9ecfae5 |
children | 194eb4bd202b |
rev | line source |
---|---|
23219
3ac9f9ecfae5
maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents:
23083
diff
changeset
|
1 ## Copyright (C) 1995-2017 Kurt Hornik |
9093 | 2 ## Copyright (C) 2009 VZLU Prague |
3426 | 3 ## |
3922 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
8 ## the Free Software Foundation; either version 3 of the License, or |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
9 ## (at your option) any later version. |
3426 | 10 ## |
3922 | 11 ## Octave is distributed in the hope that it will be useful, but |
2540 | 12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
14 ## GNU General Public License for more details. |
3426 | 15 ## |
2540 | 16 ## You should have received a copy of the GNU General Public License |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
2540 | 19 |
3369 | 20 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20160
diff
changeset
|
21 ## @deftypefn {} {} 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 | 23 ## the square matrix @var{x} and stacking the result one column above the |
20160
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
24 ## other. |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
25 ## |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
26 ## This has uses in matrix calculus where the underlying matrix is symmetric |
03b9d17a2d95
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
27 ## and it would be pointless to keep values above the main diagonal. |
12639
4d777e05d47c
doc: Review and update documentation for "Matrix Manipulation" chapter.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 ## @seealso{vec} |
3369 | 29 ## @end deftypefn |
30 | |
2540 | 31 ## See Magnus and Neudecker (1988), Matrix differential calculus with |
32 ## applications in statistics and econometrics. | |
33 | |
5428 | 34 ## Author KH <Kurt.Hornik@wu-wien.ac.at> |
2540 | 35 ## Created: 8 May 1995 |
36 ## Adapted-By: jwe | |
37 | |
38 function v = vech (x) | |
3426 | 39 |
2540 | 40 if (nargin != 1) |
6046 | 41 print_usage (); |
2540 | 42 endif |
3426 | 43 |
4030 | 44 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
|
45 error ("vech: X must be square"); |
2540 | 46 endif |
3426 | 47 |
2540 | 48 n = rows (x); |
9093 | 49 slices = cellslices (x(:), (1:n) + n*(0:n-1), n*(1:n)); |
50 v = vertcat (slices{:}); | |
2540 | 51 |
52 endfunction | |
7411 | 53 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
54 |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 %!assert (vech ([1, 2, 3; 4, 5, 6; 7, 8, 9]), [1; 4; 7; 5; 8; 9]) |
7411 | 56 |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!error vech () |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 %!error vech (1, 2) |