Mercurial > hg > octave-max
comparison scripts/sparse/pcr.m @ 14335:ce2b59a6d0e5
maint: periodic merge of stable to default.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 05 Feb 2012 15:32:24 -0800 |
parents | 11949c9795a0 4d917a6a858b |
children | f3d52523cde1 |
comparison
equal
deleted
inserted
replaced
14333:6dd710b73150 | 14335:ce2b59a6d0e5 |
---|---|
99 ## Let us consider a trivial problem with a diagonal matrix (we exploit the | 99 ## Let us consider a trivial problem with a diagonal matrix (we exploit the |
100 ## sparsity of A) | 100 ## sparsity of A) |
101 ## | 101 ## |
102 ## @example | 102 ## @example |
103 ## @group | 103 ## @group |
104 ## n = 10; | 104 ## n = 10; |
105 ## A = sparse (diag (1:n)); | 105 ## A = sparse (diag (1:n)); |
106 ## b = rand (N, 1); | 106 ## b = rand (N, 1); |
107 ## @end group | 107 ## @end group |
108 ## @end example | 108 ## @end example |
109 ## | 109 ## |
110 ## @sc{Example 1:} Simplest use of @code{pcr} | 110 ## @sc{Example 1:} Simplest use of @code{pcr} |
111 ## | 111 ## |
112 ## @example | 112 ## @example |
113 ## x = pcr (A, b) | 113 ## x = pcr (A, b) |
114 ## @end example | 114 ## @end example |
115 ## | 115 ## |
116 ## @sc{Example 2:} @code{pcr} with a function which computes | 116 ## @sc{Example 2:} @code{pcr} with a function which computes |
117 ## @code{@var{A} * @var{x}}. | 117 ## @code{@var{A} * @var{x}}. |
118 ## | 118 ## |
119 ## @example | 119 ## @example |
120 ## @group | 120 ## @group |
121 ## function y = apply_a (x) | 121 ## function y = apply_a (x) |
122 ## y = [1:10]'.*x; | 122 ## y = [1:10]' .* x; |
123 ## endfunction | 123 ## endfunction |
124 ## | 124 ## |
125 ## x = pcr ("apply_a", b) | 125 ## x = pcr ("apply_a", b) |
126 ## @end group | 126 ## @end group |
127 ## @end example | 127 ## @end example |
128 ## | 128 ## |
129 ## @sc{Example 3:} Preconditioned iteration, with full diagnostics. The | 129 ## @sc{Example 3:} Preconditioned iteration, with full diagnostics. The |
130 ## preconditioner (quite strange, because even the original matrix | 130 ## preconditioner (quite strange, because even the original matrix |
131 ## @var{A} is trivial) is defined as a function | 131 ## @var{A} is trivial) is defined as a function |
132 ## | 132 ## |
133 ## @example | 133 ## @example |
134 ## @group | 134 ## @group |
135 ## function y = apply_m (x) | 135 ## function y = apply_m (x) |
136 ## k = floor (length(x)-2); | 136 ## k = floor (length (x) - 2); |
137 ## y = x; | 137 ## y = x; |
138 ## y(1:k) = x(1:k)./[1:k]'; | 138 ## y(1:k) = x(1:k) ./ [1:k]'; |
139 ## endfunction | 139 ## endfunction |
140 ## | 140 ## |
141 ## [x, flag, relres, iter, resvec] = ... | 141 ## [x, flag, relres, iter, resvec] = ... |
142 ## pcr (A, b, [], [], "apply_m") | 142 ## pcr (A, b, [], [], "apply_m") |
143 ## semilogy([1:iter+1], resvec); | 143 ## semilogy ([1:iter+1], resvec); |
144 ## @end group | 144 ## @end group |
145 ## @end example | 145 ## @end example |
146 ## | 146 ## |
147 ## @sc{Example 4:} Finally, a preconditioner which depends on a | 147 ## @sc{Example 4:} Finally, a preconditioner which depends on a |
148 ## parameter @var{k}. | 148 ## parameter @var{k}. |
149 ## | 149 ## |
150 ## @example | 150 ## @example |
151 ## @group | 151 ## @group |
152 ## function y = apply_m (x, varargin) | 152 ## function y = apply_m (x, varargin) |
153 ## k = varargin@{1@}; | 153 ## k = varargin@{1@}; |
154 ## y = x; y(1:k) = x(1:k)./[1:k]'; | 154 ## y = x; |
155 ## endfunction | 155 ## y(1:k) = x(1:k) ./ [1:k]'; |
156 ## | 156 ## endfunction |
157 ## [x, flag, relres, iter, resvec] = ... | 157 ## |
158 ## pcr (A, b, [], [], "apply_m"', [], 3) | 158 ## [x, flag, relres, iter, resvec] = ... |
159 ## pcr (A, b, [], [], "apply_m"', [], 3) | |
159 ## @end group | 160 ## @end group |
160 ## @end example | 161 ## @end example |
161 ## | 162 ## |
162 ## References: | 163 ## References: |
163 ## | 164 ## |