Mercurial > hg > octave-lyh
changeset 2540:c3d634d49ce4
[project @ 1996-11-20 00:20:12 by jwe]
author | jwe |
---|---|
date | Wed, 20 Nov 1996 00:21:25 +0000 |
parents | 1dca28c213f0 |
children | 80a42c3fefc9 |
files | scripts/ChangeLog scripts/linear-algebra/commutation_matrix.m scripts/linear-algebra/cross.m scripts/linear-algebra/duplication_matrix.m scripts/linear-algebra/vec.m scripts/linear-algebra/vech.m |
diffstat | 6 files changed, 257 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,21 @@ +Tue Nov 19 15:13:35 1996 John W. Eaton <jwe@bevo.che.wisc.edu> + + * linear-algebra/commutation_matrix.m, linear-algebra/cross.m, + linear-algebra/duplication_matrix.m, linear-algebra/vec.m, + linear-algebra/vech.m: New files from Kurt Hornik. + + * general/nextpow2.m, general/shift.m, general/diff.m, + general/common_size.m: New files from Kurt Hornik. + + * miscellaneous/bincoeff.m, miscellaneous/xor.m: + New files from Kurt Hornik. + + * signal/detrend.m: New file from Kurt Hornik. + + * specfun/betai.m, specfun/gammai.m, specfun/erfinv.m, + specfun/pow2.m, specfun/log2.m: + New files and updates from Kurt Hornik. + Fri Nov 15 18:13:00 1996 John W. Eaton <jwe@bevo.che.wisc.edu> * plot/__plt__.m: Add explicit replot after last command is
new file mode 100644 --- /dev/null +++ b/scripts/linear-algebra/commutation_matrix.m @@ -0,0 +1,55 @@ +## Copyright (C) 1995, 1996 Kurt Hornik +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this file. If not, write to the Free Software Foundation, +## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +## usage: commutation_matrix (m [, n]) +## +## Returns the commutation matrix K_{m,n} which is the unique m*n by +## m*n matrix such that K_{m,n} * vec (A) = vec (A') for all m by n +## matrices A. +## +## If only one argument m is given, K_{m,m} is returned. +## +## See Magnus and Neudecker (1988), Matrix differential calculus with +## applications in statistics and econometrics. + +## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> +## Created: 8 May 1995 +## Adapted-By: jwe + +function k = commutation_matrix (m, n) + + if (nargin < 1 || nargin > 2) + usage ("commutation_matrix (m [, n])"); + else + if (! (is_scalar (m) && m == round (m) && m > 0)) + error ("commutation_matrix: m must be a positive integer"); + endif + if (nargin == 1) + n = m; + elseif (! (is_scalar (n) && n == round (n) && n > 0)) + error ("commutation_matrix: n must be a positive integer"); + endif + endif + + ## It is clearly possible to make this a LOT faster! + k = zeros (m * n, m * n); + for i = 1 : m + for j = 1 : n + k ((i - 1) * n + j, (j - 1) * m + i) = 1; + endfor + endfor + +endfunction
new file mode 100644 --- /dev/null +++ b/scripts/linear-algebra/cross.m @@ -0,0 +1,44 @@ +## Copyright (C) 1995, 1996 Kurt Hornik +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this file. If not, write to the Free Software Foundation, +## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +## usage: cross (x, y) +## +## Computes the vector cross product of the two 3-dimensional vectors +## x and y. + +## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> +## Created: 15 October 1994 +## Adapted-By: jwe + +function z = cross (x, y) + + if (nargin != 2) + usage ("cross (x, y)"); + endif + + if (! (is_vector (x) && length (x) == 3 + && is_vector (y) && length (y) == 3)) + error ("cross: both x and y must be 3-dimensional vectors"); + endif + + x = reshape (x, 3, 1); + y = reshape (y, 3, 1); + e = eye (3, 3); + for k = 1 : 3 + z(k) = det ([x y e(:, k)]); + endfor + +endfunction
new file mode 100644 --- /dev/null +++ b/scripts/linear-algebra/duplication_matrix.m @@ -0,0 +1,53 @@ +## Copyright (C) 1995, 1996 Kurt Hornik +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this file. If not, write to the Free Software Foundation, +## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +## usage: duplication_matrix (n) +## +## Returns the duplication matrix D_n which is the unique n^2 by +## n*(n+1)/2 matrix such that D_n * vech (A) = vec (A) for all +## symmetric n by n matrices A. +## +## See Magnus and Neudecker (1988), Matrix differential calculus with +## applications in statistics and econometrics. + +## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> +## Created: 8 May 1995 +## Adapged-By: jwe + +function d = duplication_matrix (n) + + if (nargin != 1) + usage ("duplication_matrix (n)"); + endif + + if (! (is_scalar (n) && n == round (n) && n > 0)) + error ("duplication_matrix: n must be a positive integer"); + endif + + d = zeros (n * n, n * (n + 1) / 2); + + ## It is clearly possible to make this a LOT faster! + count = 0; + for j = 1 : n + d ((j - 1) * n + j, count + j) = 1; + for i = (j + 1) : n + d ((j - 1) * n + i, count + i) = 1; + d ((i - 1) * n + j, count + i) = 1; + endfor + count = count + n - j; + endfor + +endfunction
new file mode 100644 --- /dev/null +++ b/scripts/linear-algebra/vec.m @@ -0,0 +1,37 @@ +## Copyright (C) 1995, 1996 Kurt Hornik +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this file. If not, write to the Free Software Foundation, +## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +## usage: vec (x) +## +## Returns vec (x), the vector obtained by stacking the columns of x +## one above the other. +## +## See Magnus and Neudecker (1988), Matrix differential calculus with +## applications in statistics and econometrics. + +## Author: KH <Kurt.Hornik@ci.tuwien.ac.at> +## Created: 8 May 1995 +## Adapted-By: jwe + +function v = vec (x) + + if (nargin != 1) + usage ("vec (x)"); + endif + + v = reshape (x, prod (size (x)), 1); + +endfunction
new file mode 100644 --- /dev/null +++ b/scripts/linear-algebra/vech.m @@ -0,0 +1,50 @@ +## Copyright (C) 1995, 1996 Kurt Hornik +## +## This program is free software; you can redistribute it and/or modify +## it under the terms of the GNU General Public License as published by +## the Free Software Foundation; either version 2, or (at your option) +## any later version. +## +## This program is distributed in the hope that it will be useful, but +## WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +## General Public License for more details. +## +## You should have received a copy of the GNU General Public License +## along with this file. If not, write to the Free Software Foundation, +## 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +## usage: vech (x) +## +## For square x, returns the vector vech (x) which is obtained from x +## by eliminating all supradiagonal elements and stacking the result +## one column above the other. +## +## See Magnus and Neudecker (1988), Matrix differential calculus with +## applications in statistics and econometrics. + +## Author KH <Kurt.Hornik@ci.tuwien.ac.at> +## Created: 8 May 1995 +## Adapted-By: jwe + +function v = vech (x) + + if (nargin != 1) + usage ("vech (x)"); + endif + + if (! is_square (x)) + error ("vech: x must be square"); + endif + + ## This should be quicker than having an inner `for' loop as well. + ## Ideally, vech should be written in C++. + n = rows (x); + count = 0; + for j = 1 : n + i = j : n; + v (count + i) = x (i, j); + count = count + n - j; + endfor + +endfunction