Last active
June 8, 2018 13:46
-
-
Save higham/6c00f62e48c1b0116f2e9a8f43f2e02a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function F = funm_randomized(A,fun) | |
%FUNM_RANDOMIZED Evaluate general matrix function using | |
% randomized approximate diagonalization method of Davies (2007). | |
tol = 8*eps(A(1,1)); % Tolerance for single or double precision A. | |
E = randn(size(A)); | |
[V,D] = eig(A + (tol*norm(A,'fro')/norm(E,'fro'))*E); | |
F = V*diag(fun(diag(D)))/V; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks, Pavel - that's an excellent point. E should indeed be of the same precision as A and your change achieves that very neatly.