comparison mftoolbox/funm_simple.m @ 0:8f23314345f4 draft

Create local repository for matrix toolboxes. Step #0 done.
author Antonio Pino Robles <data.script93@gmail.com>
date Wed, 06 May 2015 14:56:53 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8f23314345f4
1 function F = funm_simple(A,fun)
2 %FUNM_SIMPLE Simplified Schur-Parlett method for function of a matrix.
3 % F = FUNM_SIMPLE(A,FUN) evaluates the function FUN at the
4 % square matrix A by the Schur-Parlett method using the scalar
5 % Parlett recurrence (and hence without blocking or reordering).
6 % This function is intended for matrices with distinct eigenvalues
7 % only and can be numerically unstable.
8 % FUNM should in general be used in preference.
9
10 n = length(A);
11
12 [Q,T] = schur(A,'complex'); % Complex Schur form.
13 F = diag(feval(fun,diag(T))); % Diagonal of F.
14
15 % Compute off-diagonal of F by scalar Parlett recurrence.
16 for j=2:n
17 for i = j-1:-1:1
18 s = T(i,j)*(F(i,i)-F(j,j));
19 if j-i >= 2
20 k = i+1:j-1;
21 s = s + F(i,k)*T(k,j) - T(i,k)*F(k,j);
22 end
23 d = T(i,i) - T(j,j);
24 if d ~= 0
25 F(i,j) = s/d;
26 end
27 end
28 end
29
30 F = Q*F*Q';