funcAtMatrix(func, mat)

Evaluates a square matrix at a function.

funcThe function to be evaluated.
matThe matrix to be used.
return valuefunc(mat)

(Diagonalisable matrices are supported currently.)

a = [827,444;42,888]; a = a/max(abs(eig(a))); e = ejs.funcAtMatrix(@(x) x^3, a) e - a*a*a e = ejs.funcAtMatrix(@(x) x^827, a) eig(e)
// Compares the power series to the evaluation. n = 5; a = rand(n) a /= (max(abs(eig(a)))+1e-8); // so as to avoid numerical instability in the powers f = ejs.funcAtMatrix(@(x) exp(x), a) e = eye(n); q = e; for (j=1; j<18; ++j) { q *= a/j; e += q; } max(abs(e-f))