Mercurial > matrix-functions
comparison toolbox/dorr.m @ 2:c124219d7bfa draft
Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author | Antonio Pino Robles <data.script93@gmail.com> |
---|---|
date | Thu, 07 May 2015 18:36:24 +0200 |
parents | 8f23314345f4 |
children |
comparison
equal
deleted
inserted
replaced
1:e471a92d17be | 2:c124219d7bfa |
---|---|
1 function [c, d, e] = dorr(n, theta) | |
2 %DORR Dorr matrix - diagonally dominant, ill conditioned, tridiagonal. | |
3 % [C, D, E] = DORR(N, THETA) returns the vectors defining a row diagonally | |
4 % dominant, tridiagonal M-matrix that is ill conditioned for small | |
5 % values of the parameter THETA >= 0. | |
6 % If only one output parameter is supplied then | |
7 % C = FULL(TRIDIAG(C,D,E)), i.e., the matrix iself is returned. | |
8 % The columns of INV(C) vary greatly in norm. THETA defaults to 0.01. | |
9 % The amount of diagonal dominance is given by (ignoring rounding errors): | |
10 % COMP(C)*ONES(N,1) = THETA*(N+1)^2 * [1 0 0 ... 0 1]'. | |
11 | |
12 % Reference: | |
13 % F.W. Dorr, An example of ill-conditioning in the numerical | |
14 % solution of singular perturbation problems, Math. Comp., 25 (1971), | |
15 % pp. 271-283. | |
16 | |
17 if nargin < 2, theta = 0.01; end | |
18 | |
19 c = zeros(n,1); e = c; d = c; | |
20 % All length n for convenience. Make c, e of length n-1 later. | |
21 | |
22 h = 1/(n+1); | |
23 m = floor( (n+1)/2 ); | |
24 term = theta/h^2; | |
25 | |
26 i = (1:m)'; | |
27 c(i) = -term*ones(m,1); | |
28 e(i) = c(i) - (0.5-i*h)/h; | |
29 d(i) = -(c(i) + e(i)); | |
30 | |
31 i = (m+1:n)'; | |
32 e(i) = -term*ones(n-m,1); | |
33 c(i) = e(i) + (0.5-i*h)/h; | |
34 d(i) = -(c(i) + e(i)); | |
35 | |
36 c = c(2:n); | |
37 e = e(1:n-1); | |
38 | |
39 if nargout <= 1 | |
40 c = tridiag(c, d, e); | |
41 end |