Mathematica provides the built-in command MatrixLog
, which operates on a square nonsingular matrix, but it returns the natural logarithm.
How can I find the base 2 logarithm of a matrix?
Perhaps
MatrixLog[ m ] / Log[2]
I write this answer with the caveat that I don't have Mathematica version 9 or later (the versions which now have this very belated function built-in), but with said caveat being offset by knowing a thing or two about the function of a matrix. ;)
I'd have to agree with george's take that the docs for MatrixFunction[]
could probably have explained things a bit better, so here's my take.
Here's a short description:
MatrixFunction[]
is the Mathematica equivalent of MATLAB'sfunm()
.
Hmm, that's a tad too short. How about another one?
MatrixFunction[f, A]
evaluates, for a given square matrix $\mathbf A$ and a given scalar-valued function $f(x)$, the contour integral $$f(\mathbf A) = \frac{1}{2\pi i} \oint_\gamma f(z)\, (z \mathbf I- \mathbf A)^{-1}\,\mathrm dz$$ where $\gamma$ is a closed contour enclosing the eigenvalues of $\mathbf A$, and where $f(z)$ is analytic within.
(adapted from here)
Correct, but prolly too technical for the lot of you.
Here, then, is an informal description: if you look at however your given function is defined for scalar arguments, MatrixFunction[]
evaluates the result of what happens if you formally replace the scalar argument with a matrix argument. For instance, if you imagine the usual Taylor series for the logarithm $\log z$, the series you get by replacing $z$ with $\mathbf A$ (and interpreting matrix powers in the sense of MatrixPower[]
) is what is evaluated by MatrixFunction[Log, A]
(with analytic continuation done as needed). Thus, MatrixFunction[Log2, A]
is the function wanted by the OP. (But, as kglr notes, since MatrixLog[]
is built-in, and presumably uses specialized, more efficient algorithms under the hood (I hope!), it is better to use this specialized function and subsequently convert the natural logarithm to a binary logarithm through the usual base-change identity.)
For people who are interested in further details, I will recommend reading Functions of Matrices: Theory and Computation by Nick Higham; it discusses a number of algorithms for evaluation, including the standard Schur-Parlett algorithm used internally by both Mathematica and MATLAB.
MatrixLog[]
would use something like inverse scaling + squaring internally; guess not.
$\endgroup$
Commented
Oct 9, 2015 at 13:34
MatrixFunction[Log[2, #] &, {{1., 1., 0.}, {0., 1., 0.}, {0., 0., 2.}}]
$\endgroup$MatrixLog[m]/Log[2]
?? $\endgroup$MatrixFunction
on this site, and an expansion of @Sektor's comment (with a better question title) might make this a useful question to keep around. $\endgroup$