comparison toolbox/see.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 e0817ccb2834
comparison
equal deleted inserted replaced
1:e471a92d17be 2:c124219d7bfa
1 function see(A, k)
2 %SEE Pictures of a matrix and its (pseudo-) inverse.
3 % SEE(A) displays MESH(A), MESH(PINV(A)), SEMILOGY(SVD(A),'o'),
4 % and (if A is square) FV(A) in four subplot windows.
5 % SEE(A, 1) plots an approximation to the pseudospectrum in the
6 % third window instead of the singular values.
7 % SEE(A, -1) plots only the eigenvalues in the fourth window,
8 % which is much quicker than plotting the field of values.
9 % If A is complex, only real parts are used for the mesh plots.
10 % If A is sparse, just SPY(A) is shown.
11
12 if nargin < 2, k = 0; end
13 [m, n] = size(A);
14 square = (m == n);
15 clf
16
17 if issparse(A)
18
19 spy(A);
20
21 else
22
23 B = pinv(A);
24 s = svd(A);
25 zs = (s == zeros(size(s)));
26 if any( zs )
27 s( zs ) = []; % Remove zero singular values for semilogy plot.
28 end
29
30 subplot(2,2,1)
31 mesh(real(A)), axis('ij'), drawnow
32 subplot(2,2,2)
33 mesh(real(B)), axis('ij'), drawnow
34
35 if k <= 0
36 subplot(2,2,3)
37 semilogy(s, 'og')
38 hold on, semilogy(s, '-'), hold off, drawnow
39 if any(zs), subplot(2,2,3), title('Zero(s) omitted'), subplot(2,2,4), end
40 elseif k == 1
41 subplot(2,2,3)
42 ps(A); drawnow
43 end
44
45 if square
46 if k == -1
47 subplot(2,2,4)
48 ps(A, 0);
49 else
50 subplot(2,2,4)
51 fv(A);
52 end
53 else
54 if k == 0
55 subplot(2,2,4)
56 axis off
57 else
58 clf
59 end
60 text(0,0,'Matrix not square.')
61 end
62 subplot;
63
64 end