Mercurial > hg > octave-nkf
annotate scripts/sparse/speye.m @ 12556:88558b8eb8a7
Add deprecated entry for cquad() pointing to quadcc().
HG Enter commit message. Lines beginning with 'HG:' are removed.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Thu, 31 Mar 2011 09:57:11 -0700 |
parents | c792872f8942 |
children | d0b799dafede |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 2004-2011 David Bateman and Andy Adler |
5164 | 2 ## |
7016 | 3 ## This file is part of Octave. |
5164 | 4 ## |
7016 | 5 ## Octave is free software; you can redistribute it and/or modify it |
6 ## under the terms of the GNU General Public License as published by | |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
9 ## | |
10 ## Octave is distributed in the hope that it will be useful, but | |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
5164 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
5164 | 18 |
19 ## -*- texinfo -*- | |
10793
be55736a0783
Grammarcheck the documentation from m-files.
Rik <octave@nomad.inbox5.com>
parents:
9245
diff
changeset
|
20 ## @deftypefn {Function File} {@var{y} =} speye (@var{m}) |
5164 | 21 ## @deftypefnx {Function File} {@var{y} =} speye (@var{m}, @var{n}) |
22 ## @deftypefnx {Function File} {@var{y} =} speye (@var{sz}) | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
23 ## Returns a sparse identity matrix. This is significantly more |
5164 | 24 ## efficient than @code{sparse (eye (@var{m}))} as the full matrix |
25 ## is not constructed. | |
26 ## | |
27 ## Called with a single argument a square matrix of size @var{m} by | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
7017
diff
changeset
|
28 ## @var{m} is created. Otherwise a matrix of @var{m} by @var{n} is |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## created. If called with a single vector argument, this argument |
5164 | 30 ## is taken to be the size of the matrix to create. |
31 ## @end deftypefn | |
32 | |
6498 | 33 function s = speye (m, n) |
5164 | 34 if (nargin == 1) |
35 if (isvector (m) && length(m) == 2) | |
36 n = m(2); | |
37 m = m(1); | |
38 elseif (isscalar (m)) | |
39 n = m; | |
40 else | |
41 error ("speye: invalid matrix dimension"); | |
42 endif | |
43 else | |
6498 | 44 if (! isscalar (m) || ! isscalar (n)) |
5164 | 45 error ("speye: invalid matrix dimension"); |
46 endif | |
47 endif | |
48 | |
6498 | 49 lo = min ([m, n]); |
50 s = sparse (1:lo, 1:lo, 1, m, n); | |
5164 | 51 endfunction |
52 | |
53 %!assert(issparse(speye(4))) | |
54 %!assert(speye(4),sparse(1:4,1:4,1)) | |
55 %!assert(speye(2,4),sparse(1:2,1:2,1,2,4)) | |
56 %!assert(speye(4,2),sparse(1:2,1:2,1,4,2)) | |
57 %!assert(speye([4,2]),sparse(1:2,1:2,1,4,2)) |