annotate scripts/sparse/cgs.m @ 21633:dcf8922b724b

Deprecate printf, puts, and scanf. Make fputs a M-file. * libinterp/corefcn/file-io.cc: extracted printf, puts, and scanf to M-files. * scripts/deprecated/printf.m: new function, equivalent to version file-io.cc. * scripts/deprecated/puts.m: new function, equivalent to version file-io.cc. * scripts/deprecated/scanf.m: new function, equivalent to version file-io.cc. * scripts/deprecated/module.mk: added printf, puts, and scanf. * scripts/io/fputs.m: new function, equivalent to version file-io.cc. * scripts/io/module.mk: added fputs. * doc/interpreter/io.txi: adapted documentation to current implementation. * NEWS: announced changes. * doc/interpreter/basics.txi: replaced printf by fprintf. * doc/interpreter/stmt.txi: replaced printf by fprintf. * doc/interpreter/var.txi: replaced printf by fprintf. * doc/refcard/refcard.tex: removed printf and scanf. * examples/code/@FIRfilter/display.m: replaced printf by fprintf. * examples/code/@polynomial/display.m: replaced printf by fprintf. * scripts/@ftp/display.m: replaced printf by fprintf. * scripts/general/inputParser.m: replaced printf by fprintf. * scripts/general/methods.m: replaced printf by fprintf. * scripts/general/profexplore.m: replaced printf by fprintf. * scripts/general/profshow.m: replaced printf by fprintf. * scripts/help/help.m: replaced puts by fputs and printf by fprintf. * scripts/help/lookfor.m: replaced puts by fputs and printf by fprintf. * scripts/help/which.m: replaced printf by fprintf. * scripts/image/imformats.m: replaced printf by fprintf. * scripts/io/beep.m: replaced puts by fputs. * scripts/io/textread.m: replaced printf by fprintf. * scripts/java/javaclasspath.m: replaced printf by fprintf. * scripts/java/javamem.m: replaced printf by fprintf. * scripts/miscellaneous/dir.m: replaced printf by fprintf. * scripts/miscellaneous/dos.m: replaced printf by fprintf. * scripts/miscellaneous/fact.m: replaced printf by fprintf. * scripts/miscellaneous/info.m: replaced printf by fprintf. * scripts/miscellaneous/license.m: replaced printf by fprintf. * scripts/miscellaneous/ls.m: replaced puts by fputs. * scripts/miscellaneous/menu.m: replaced printf by fprintf. * scripts/miscellaneous/mkoctfile.m: replaced printf by fprintf. * scripts/miscellaneous/private/display_info_file.m: * scripts/miscellaneous/unix.m: replaced printf by fprintf. * scripts/miscellaneous/ver.m: replaced printf by fprintf. * scripts/miscellaneous/what.m: replaced printf by fprintf. * scripts/ode/ode23.m: replaced printf by fprintf. * scripts/ode/ode45.m: replaced printf by fprintf. * scripts/optimization/fminbnd.m: replaced printf by fprintf. * scripts/optimization/optimset.m: replaced puts by fputs and printf by fprintf. * scripts/optimization/sqp.m: replaced printf by fprintf. * scripts/pkg/pkg.m: replaced printf by fprintf. * scripts/pkg/private/describe.m: replaced printf by fprintf. * scripts/pkg/private/install.m: replaced printf by fprintf. * scripts/pkg/private/installed_packages.m: replaced printf by fprintf. * scripts/pkg/private/list_forge_packages.m: replaced puts by fputs and printf by fprintf. * scripts/pkg/private/rebuild.m: replaced printf by fprintf. * scripts/plot/util/__gnuplot_drawnow__.m: replaced puts by fputs and printf by fprintf. * scripts/signal/stft.m: replaced printf by fprintf. * scripts/sparse/bicg.m: replaced printf by fprintf. * scripts/sparse/bicgstab.m: replaced printf by fprintf. * scripts/sparse/cgs.m: replaced printf by fprintf. * scripts/sparse/pcg.m: replaced printf by fprintf. * scripts/sparse/pcr.m: replaced printf by fprintf. * scripts/sparse/qmr.m: replaced printf by fprintf. * scripts/statistics/models/logistic_regression.m: replaced printf by fprintf. * scripts/statistics/tests/anova.m: replaced printf by fprintf. * scripts/statistics/tests/bartlett_test.m: replaced printf by fprintf. * scripts/statistics/tests/chisquare_test_homogeneity.m: replaced printf by fprintf. * scripts/statistics/tests/chisquare_test_independence.m: replaced printf by fprintf. * scripts/statistics/tests/cor_test.m: replaced printf by fprintf. * scripts/statistics/tests/f_test_regression.m: replaced printf by fprintf. * scripts/statistics/tests/hotelling_test.m: replaced printf by fprintf. * scripts/statistics/tests/hotelling_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/kolmogorov_smirnov_test.m: replaced printf by fprintf. * scripts/statistics/tests/kolmogorov_smirnov_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/kruskal_wallis_test.m: replaced printf by fprintf. * scripts/statistics/tests/manova.m: replaced printf by fprintf. * scripts/statistics/tests/mcnemar_test.m: replaced printf by fprintf. * scripts/statistics/tests/prop_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/run_test.m: replaced printf by fprintf. * scripts/statistics/tests/sign_test.m: replaced printf by fprintf. * scripts/statistics/tests/t_test.m: replaced printf by fprintf. * scripts/statistics/tests/t_test_2.m: replaced printf by fprintf. * scripts/statistics/tests/t_test_regression.m: replaced printf by fprintf. * scripts/statistics/tests/u_test.m: replaced printf by fprintf. * scripts/statistics/tests/var_test.m: replaced printf by fprintf. * scripts/statistics/tests/welch_test.m: replaced printf by fprintf. * scripts/statistics/tests/wilcoxon_test.m: replaced printf by fprintf. * scripts/statistics/tests/z_test.m: replaced printf by fprintf. * scripts/statistics/tests/z_test_2.m: replaced printf by fprintf. * scripts/strings/strtok.m: replaced printf by fprintf. * scripts/testfun/__run_test_suite__.m: replaced puts by fputs and printf by fprintf. * scripts/testfun/demo.m: replaced printf by fprintf. * scripts/testfun/example.m: replaced printf by fprintf. * scripts/testfun/private/compare_plot_demos.m: replaced printf by fprintf. * scripts/testfun/rundemos.m: replaced printf by fprintf. * scripts/testfun/runtests.m: replaced puts by fputs and printf by fprintf. * scripts/testfun/speed.m: replaced printf by fprintf. * scripts/testfun/test.m: replaced printf by fprintf. * scripts/time/calendar.m: replaced puts by fputs and printf by fprintf. * test/io.tst: replaced printf by fprintf.
author Kai T. Ohlhus <k.ohlhus@gmail.com>
date Wed, 20 Apr 2016 17:53:10 +0200
parents 3be6a07e8bad
children 96518f623c91
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
19697
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
1 ## Copyright (C) 2008-2015 Radek Salac
14138
72c96de7a403 maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents: 13929
diff changeset
2 ## Copyright (C) 2012 Carlo de Falco
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
3 ##
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
4 ## This file is part of Octave.
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
5 ##
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
6 ## Octave is free software; you can redistribute it and/or modify it
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
7 ## under the terms of the GNU General Public License as published by
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
8 ## the Free Software Foundation; either version 3 of the License, or (at
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
9 ## your option) any later version.
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
10 ##
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
11 ## Octave is distributed in the hope that it will be useful, but
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
14 ## General Public License for more details.
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
15 ##
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
16 ## You should have received a copy of the GNU General Public License
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
17 ## along with Octave; see the file COPYING. If not, see
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
18 ## <http://www.gnu.org/licenses/>.
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
19
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
20 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20711
diff changeset
21 ## @deftypefn {} {@var{x} =} cgs (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{M1}, @var{M2}, @var{x0})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20711
diff changeset
22 ## @deftypefnx {} {@var{x} =} cgs (@var{A}, @var{b}, @var{rtol}, @var{maxit}, @var{P})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20711
diff changeset
23 ## @deftypefnx {} {[@var{x}, @var{flag}, @var{relres}, @var{iter}, @var{resvec}] =} cgs (@var{A}, @var{b}, @dots{})
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
24 ## Solve @code{A x = b}, where @var{A} is a square matrix, using the
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
25 ## Conjugate Gradients Squared method.
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
26 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
27 ## @itemize @minus
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
28 ## @item @var{rtol} is the relative tolerance, if not given or set to [] the
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
29 ## default value 1e-6 is used.
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
30 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
31 ## @item @var{maxit} the maximum number of outer iterations, if not given or
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
32 ## set to [] the default value @code{min (20, numel (b))} is used.
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
33 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
34 ## @item @var{x0} the initial guess, if not given or set to [] the default
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
35 ## value @code{zeros (size (b))} is used.
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
36 ## @end itemize
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
37 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
38 ## @var{A} can be passed as a matrix or as a function handle or inline
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
39 ## function @code{f} such that @code{f(x) = A*x}.
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
40 ##
20164
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
41 ## The preconditioner @var{P} is given as @code{P = M1 * M2}. Both @var{M1}
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
42 ## and @var{M2} can be passed as a matrix or as a function handle or inline
df437a52bcaf doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19854
diff changeset
43 ## function @code{g} such that @code{g(x) = M1 \ x} or @code{g(x) = M2 \ x}.
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
44 ##
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
45 ## If called with more than one output parameter
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
46 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
47 ## @itemize @minus
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
48 ## @item @var{flag} indicates the exit status:
14853
72b8b39e12be doc: Periodic grammarcheck of documentation.
Rik <octave@nomad.inbox5.com>
parents: 14609
diff changeset
49 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
50 ## @itemize @minus
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
51 ## @item 0: iteration converged to the within the chosen tolerance
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
52 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
53 ## @item 1: the maximum number of iterations was reached before convergence
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
54 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
55 ## @item 3: the algorithm reached stagnation
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
56 ## @end itemize
16816
12005245b645 doc: Periodic grammarcheck of documentation.
Rik <rik@octave.org>
parents: 14853
diff changeset
57 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
58 ## (the value 2 is unused but skipped for compatibility).
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
59 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
60 ## @item @var{relres} is the final value of the relative residual.
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
61 ##
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
62 ## @item @var{iter} is the number of iterations performed.
13929
9cae456085c2 Grammarcheck of documentation before 3.6.0 release.
Rik <octave@nomad.inbox5.com>
parents: 13141
diff changeset
63 ##
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
64 ## @item @var{resvec} is a vector containing the relative residual at
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
65 ## each iteration.
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
66 ## @end itemize
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
67 ##
19854
0a3ca546d7fc doc: Add qmr to documentation.
Rik <rik@octave.org>
parents: 19833
diff changeset
68 ## @seealso{pcg, bicgstab, bicg, gmres, qmr}
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
69 ## @end deftypefn
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
70
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
71 function [x, flag, relres, iter, resvec] = cgs (A, b, tol, maxit, M1, M2, x0)
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
72
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
73 if (nargin >= 2 && nargin <= 7 && isvector (full (b)))
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
74
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
75 if (ischar (A))
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
76 A = str2func (A);
21171
2935d56203a4 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Rik <rik@octave.org>
parents: 20164
diff changeset
77 elseif (isnumeric (A) && issquare (A))
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
78 Ax = @(x) A * x;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
79 elseif (isa (A, "function_handle"))
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
80 Ax = @(x) feval (A, x);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
81 else
20711
7b608fadc663 Make error messages more specific about the variable and problem encountered.
Rik <rik@octave.org>
parents: 20231
diff changeset
82 error ("cgs: A must be a square matrix or function");
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
83 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
84
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
85 if (nargin < 3 || isempty (tol))
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
86 tol = 1e-6;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
87 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
88
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
89 if (nargin < 4 || isempty (maxit))
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
90 maxit = min (rows (b), 20);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
91 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
92
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
93 if (nargin < 5 || isempty (M1))
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
94 M1m1x = @(x) x;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
95 elseif (ischar (M1))
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
96 M1m1x = str2func (M1);
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
97 elseif (isnumeric (M1) && ismatrix (M1))
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
98 M1m1x = @(x) M1 \ x;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
99 elseif (isa (M1, "function_handle"))
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
100 M1m1x = @(x) feval (M1, x);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
101 else
21171
2935d56203a4 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Rik <rik@octave.org>
parents: 20164
diff changeset
102 error ("cgs: preconditioner M1 must be a function or matrix");
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
103 endif
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
104
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
105 if (nargin < 6 || isempty (M2))
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
106 M2m1x = @(x) x;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
107 elseif (ischar (M2))
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
108 M2m1x = str2func (M2);
19700
00e31f316a3a Fix Matlab incompatibility of "ismatrix" (bug #42422).
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 19697
diff changeset
109 elseif (isnumeric (M2) && ismatrix (M2))
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
110 M2m1x = @(x) M2 \ x;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
111 elseif (isa (M2, "function_handle"))
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
112 M2m1x = @(x) feval (M2, x);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
113 else
21171
2935d56203a4 Fix regressions caused by ismatrix definition change (partial fix bug #47036).
Rik <rik@octave.org>
parents: 20164
diff changeset
114 error ("cgs: preconditioner M2 must be a function or matrix");
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
115 endif
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
116
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
117 precon = @(x) M2m1x (M1m1x (x));
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
118
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
119 if (nargin < 7 || isempty (x0))
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
120 x0 = zeros (size (b));
9279
1673a0dc019f fix & improve preconditioning strategy in cgs & bicgstab
Jaroslav Hajek <highegg@gmail.com>
parents: 9278
diff changeset
121 endif
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
122
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
123
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
124 x = x0;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
125
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
126 res = b - Ax (x);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
127 norm_b = norm (b);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
128 ## Vector of the residual norms for each iteration.
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
129 resvec = norm (res) / norm_b;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
130 ro = 0;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
131 ## Default behavior we don't reach tolerance tol within maxit iterations.
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
132 flag = 1;
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
133 for iter = 1:maxit
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
134
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
135 z = precon (res);
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
136
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
137 ## Cache.
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
138 ro_old = ro;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
139 ro = res' * z;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
140 if (iter == 1)
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
141 p = z;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
142 else
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
143 beta = ro / ro_old;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
144 p = z + beta * p;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
145 endif
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
146 ## Cache.
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
147 q = Ax (p);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
148 alpha = ro / (p' * q);
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 20164
diff changeset
149 x += alpha * p;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
150
20231
83792dd9bcc1 Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents: 20164
diff changeset
151 res -= alpha * q;
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
152 relres = norm (res) / norm_b;
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
153 resvec = [resvec; relres];
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
154
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
155 if (relres <= tol)
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
156 ## We reach tolerance tol within maxit iterations.
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
157 flag = 0;
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
158 break
19833
9fc020886ae9 maint: Clean up m-files to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 19700
diff changeset
159 elseif (resvec(end) == resvec(end - 1))
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
160 ## The method stagnates.
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
161 flag = 3;
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
162 break
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
163 endif
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
164 endfor
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
165
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
166 if (nargout < 1)
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
167 if (flag == 0)
21633
dcf8922b724b Deprecate printf, puts, and scanf. Make fputs a M-file.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21178
diff changeset
168 fprintf ("cgs converged at iteration %i to a solution with relative residual %e\n",
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
169 iter, relres);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
170 elseif (flag == 3)
21633
dcf8922b724b Deprecate printf, puts, and scanf. Make fputs a M-file.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21178
diff changeset
171 fprintf (["cgs stopped at iteration %i without converging to the desired tolerance %e\n",
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
172 "because the method stagnated.\n",
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
173 "The iterate returned (number %i) has relative residual %e\n"],
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
174 iter, tol, iter, relres);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
175 else
21633
dcf8922b724b Deprecate printf, puts, and scanf. Make fputs a M-file.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 21178
diff changeset
176 fprintf (["cgs stopped at iteration %i without converging to the desired tolerance %e\n",
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
177 "because the maximum number of iterations was reached.\n",
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
178 "The iterate returned (number %i) has relative residual %e\n"],
13077
1bf456b4e51c maint: style fixes for cgs
John W. Eaton <jwe@octave.org>
parents: 13076
diff changeset
179 iter, tol, iter, relres);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
180 endif
9278
2b35cb600d50 improve bicgstab and cgs
Radek Salac <salac.r@gmail.com>
parents: 8920
diff changeset
181 endif
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
182
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
183 else
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
184 print_usage ();
9278
2b35cb600d50 improve bicgstab and cgs
Radek Salac <salac.r@gmail.com>
parents: 8920
diff changeset
185 endif
2b35cb600d50 improve bicgstab and cgs
Radek Salac <salac.r@gmail.com>
parents: 8920
diff changeset
186
8338
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
187 endfunction
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
188
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
189
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
190 %!demo
a35bf360b919 Add the cgs and treelayout functions
Radek Salac <salac.r@gmail.com>
parents:
diff changeset
191 %! % Solve system of A*x=b
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
192 %! A = [5 -1 3;-1 2 -2;3 -2 3];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
193 %! b = [7;-1;4];
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
194 %! [a,b,c,d,e] = cgs (A,b)
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
195
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
196 %!shared A, b, n, M
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
197 %!
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
198 %!test
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
199 %! n = 100;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
200 %! A = spdiags ([-ones(n,1) 4*ones(n,1) -ones(n,1)], -1:1, n, n);
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
201 %! b = sum (A, 2);
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
202 %! tol = 1e-8;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
203 %! maxit = 1000;
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
204 %! M = 4*eye (n);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
205 %! [x, flag, relres, iter, resvec] = cgs (A, b, tol, maxit, M);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
206 %! assert (x, ones (size (b)), 1e-7);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
207 %!
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
208 %!test
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
209 %! tol = 1e-8;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
210 %! maxit = 15;
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
211 %!
13076
59def8890992 codesprint: avoid crash after running tests
John W. Eaton <jwe@octave.org>
parents: 13063
diff changeset
212 %! [x, flag, relres, iter, resvec] = cgs (@(x) A * x, b, tol, maxit, M);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
213 %! assert (x, ones (size (b)), 1e-7);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
214
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
215 %!test
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
216 %! n = 100;
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
217 %! tol = 1e-8;
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
218 %! a = sprand (n, n, .1);
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
219 %! A = a'*a + 100 * eye (n);
13141
e81ddf9cacd5 maint: untabify and remove trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents: 13077
diff changeset
220 %! b = sum (A, 2);
13063
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
221 %! [x, flag, relres, iter, resvec] = cgs (A, b, tol, [], diag (diag (A)));
4b110dd204b9 codesprint: Allow passing a function handle for the coefficient matrix in cgs
Carlo de Falco <kingcrimson@tiscali.it>
parents: 11587
diff changeset
222 %! assert (x, ones (size (b)), 1e-7);
14237
11949c9795a0 Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
223