Mercurial > hg > octave-nkf
annotate scripts/sparse/speye.m @ 15144:9cc337ced51a
build: Update OCTAVE_UMFPACK_SEPARATE_SPLIT macro to look for SuiteSparse header file.
* acinclude.m4: Update OCTAVE_UMFPACK_SEPARATE_SPLIT macro to look for
SuiteSparse header file.
author | Rik <rik@octave.org> |
---|---|
date | Fri, 10 Aug 2012 12:56:15 -0700 |
parents | 5d3a684236b0 |
children | d63878346099 |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12575
diff
changeset
|
1 ## Copyright (C) 2004-2012 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}) | |
12575
d0b799dafede
Grammarcheck files for 3.4.1 release.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
23 ## Return 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) |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
35 if (isvector (m) && length (m) == 2) |
5164 | 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 | |
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 (issparse (speye (4))) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 %!assert (speye (4), sparse (1:4,1:4,1)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 %!assert (speye (2,4), sparse (1:2,1:2,1,2,4)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!assert (speye (4,2), sparse (1:2,1:2,1,4,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
58 %!assert (speye ([4,2]), sparse (1:2,1:2,1,4,2)) |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
59 |