-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathnormAm.m
52 lines (41 loc) · 1.36 KB
/
normAm.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function [c,mv] = normAm(A,m)
%NORMAM Estimate of 1-norm of power of matrix.
% NORMAM(A,m) estimates norm(A^m,1).
% If A has nonnegative elements the estimate is exact.
% [C,MV] = NORMAM(A,m) returns the estimate C and the number MV of
% matrix-vector products computed involving A or A^*.
% Reference: A. H. Al-Mohy and N. J. Higham, A New Scaling and Squaring
% Algorithm for the Matrix Exponential, SIAM J. Matrix Anal. Appl. 31(3):
% 970-989, 2009.
% Awad H. Al-Mohy and Nicholas J. Higham, September 7, 2010.
t = 1; % Number of columns used by NORMEST1.
n = length(A);
if isequal(A,abs(A))
e = ones(n,1);
for j=1:m % for positive matrices only
e = A'*e;
end
c = norm(e,inf);
mv = m;
else
[c,v,w,it] = normest1(@afun_power,t);
mv = it(2)*t*m;
end
function Z = afun_power(flag,X)
%AFUN_POWER Function to evaluate matrix products needed by NORMEST1.
if isequal(flag,'dim')
Z = n;
elseif isequal(flag,'real')
Z = isreal(A);
else
[p,q] = size(X);
if p ~= n, error('Dimension mismatch'), end
if isequal(flag,'notransp')
for i = 1:m, X = A*X; end
elseif isequal(flag,'transp')
for i = 1:m, X = A'*X; end
end
Z = X;
end
end
end