# Logarithm of a matrix in base 2?

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?

• MatrixFunction[Log[2, #] &, {{1., 1., 0.}, {0., 1., 0.}, {0., 0., 2.}}] Commented Nov 13, 2014 at 20:30
• MatrixLog[m]/Log[2]??
– kglr
Commented Nov 13, 2014 at 20:34
• not related to the question, but this might be the worst function description I've ever seen.. "gives the matrix generated by the scalar function f at the matrix argument m." Commented Nov 13, 2014 at 21:06
• There are few examples of 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. Commented Nov 14, 2014 at 1:58

Perhaps

MatrixLog[ m ] / Log[2]

• This is generally correct? Commented Feb 6, 2018 at 6:19
• @AimForClarity, not sure.
– kglr
Commented Feb 6, 2018 at 6:38
• @Aim, yes. You can show this through the contour integral definition in my answer. Commented May 2, 2020 at 15:42

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's funm().

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.

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.)
• I'd definitely be interested in seeing them! But, I'd thought MatrixLog[] would use something like inverse scaling + squaring internally; guess not. Commented Oct 9, 2015 at 13:34