Mercurial > hg > octave-nkf
annotate scripts/sparse/spaugment.m @ 20305:c164cfc24bdd
QtHandles: add annotations dialog
* libgui/graphics/annotation-dialog.h: new file
* libgui/graphics/annotation-dialog.cc: new file
* libgui/graphics/annotation-dialog.ui: new file
* libgui/graphics/Canvas.cc
(canvasMousePressEvent): call annotation_dialog when in TextMode.
* libgui/graphics/module.mk: add annotation-dialog to build
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Sun, 19 Apr 2015 09:54:54 -0400 |
parents | 9fc020886ae9 |
children | df437a52bcaf |
rev | line source |
---|---|
19898
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
19004
diff
changeset
|
1 ## Copyright (C) 2008-2015 David Bateman |
7681 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
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. | |
14 ## | |
15 ## You should have received a copy of the GNU General Public License | |
16 ## along with Octave; see the file COPYING. If not, see | |
17 ## <http://www.gnu.org/licenses/>. | |
18 | |
19 ## -*- texinfo -*- | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {@var{s} =} spaugment (@var{A}, @var{c}) |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
21 ## Create the augmented matrix of @var{A}. |
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
22 ## |
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
23 ## This is given by |
7681 | 24 ## |
25 ## @example | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
26 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
27 ## [@var{c} * eye(@var{m}, @var{m}), @var{A}; |
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
28 ## @var{A}', zeros(@var{n}, @var{n})] |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
29 ## @end group |
7681 | 30 ## @end example |
31 ## | |
32 ## @noindent | |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
33 ## This is related to the least squares solution of |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
34 ## @code{@var{A} \ @var{b}}, by |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
35 ## |
7681 | 36 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
37 ## @group |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
38 ## @var{s} * [ @var{r} / @var{c}; x] = [ @var{b}, zeros(@var{n}, columns(@var{b})) ] |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
39 ## @end group |
7681 | 40 ## @end example |
41 ## | |
42 ## @noindent | |
43 ## where @var{r} is the residual error | |
44 ## | |
45 ## @example | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
46 ## @var{r} = @var{b} - @var{A} * @var{x} |
7681 | 47 ## @end example |
48 ## | |
49 ## As the matrix @var{s} is symmetric indefinite it can be factorized | |
50 ## with @code{lu}, and the minimum norm solution can therefore be found | |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
51 ## without the need for a @code{qr} factorization. As the residual |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
52 ## error will be @code{zeros (@var{m}, @var{m})} for underdetermined |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
53 ## problems, and example can be |
7681 | 54 ## |
55 ## @example | |
56 ## @group | |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 ## m = 11; n = 10; mn = max (m, n); |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
58 ## A = spdiags ([ones(mn,1), 10*ones(mn,1), -ones(mn,1)], |
8516 | 59 ## [-1, 0, 1], m, n); |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
60 ## x0 = A \ ones (m,1); |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
61 ## s = spaugment (A); |
7681 | 62 ## [L, U, P, Q] = lu (s); |
63 ## x1 = Q * (U \ (L \ (P * [ones(m,1); zeros(n,1)]))); | |
64 ## x1 = x1(end - n + 1 : end); | |
65 ## @end group | |
66 ## @end example | |
67 ## | |
68 ## To find the solution of an overdetermined problem needs an estimate | |
69 ## of the residual error @var{r} and so it is more complex to formulate | |
70 ## a minimum norm solution using the @code{spaugment} function. | |
71 ## | |
72 ## In general the left division operator is more stable and faster than | |
73 ## using the @code{spaugment} function. | |
19004
53af80da6781
doc: Update documentation of sparse functions including seealso links.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 ## @seealso{mldivide} |
7681 | 75 ## @end deftypefn |
76 | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
77 function s = spaugment (A, c) |
7681 | 78 if (nargin < 2) |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
79 if (issparse (A)) |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
80 c = max (max (abs (A))) / 1000; |
7681 | 81 else |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
82 if (ndims (A) != 2) |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
83 error ("spaugment: expecting 2-dimenisional matrix"); |
7681 | 84 else |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
85 c = max (abs (A(:))) / 1000; |
7681 | 86 endif |
87 endif | |
20038
9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents:
19898
diff
changeset
|
88 elseif (! isscalar (c)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
11471
diff
changeset
|
89 error ("spaugment: C must be a scalar"); |
7681 | 90 endif |
91 | |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
92 [m, n] = size (A); |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
93 s = [ c * speye(m, m), A; A', sparse(n, n)]; |
7681 | 94 endfunction |
95 | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
96 |
8871 | 97 %!testif HAVE_UMFPACK |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
98 %! m = 11; n = 10; mn = max (m ,n); |
11471
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
99 %! A = spdiags ([ones(mn,1), 10*ones(mn,1), -ones(mn,1)],[-1,0,1], m, n); |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
100 %! x0 = A \ ones (m,1); |
994e2a93a8e2
Use uppercase 'A' to refer to matrix inputs in m-files.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
101 %! s = spaugment (A); |
7681 | 102 %! [L, U, P, Q] = lu (s); |
103 %! x1 = Q * (U \ (L \ (P * [ones(m,1); zeros(n,1)]))); | |
104 %! x1 = x1(end - n + 1 : end); | |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
105 %! assert (x1, x0, 1e-6); |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14327
diff
changeset
|
106 |