3
$\begingroup$

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?

$\endgroup$
4
  • 1
    $\begingroup$ MatrixFunction[Log[2, #] &, {{1., 1., 0.}, {0., 1., 0.}, {0., 0., 2.}}] $\endgroup$
    – Sektor
    Commented Nov 13, 2014 at 20:30
  • 6
    $\begingroup$ MatrixLog[m]/Log[2]?? $\endgroup$
    – kglr
    Commented Nov 13, 2014 at 20:34
  • $\begingroup$ 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." $\endgroup$
    – george2079
    Commented Nov 13, 2014 at 21:06
  • $\begingroup$ 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. $\endgroup$ Commented Nov 14, 2014 at 1:58

2 Answers 2

10
$\begingroup$

Perhaps

MatrixLog[ m ] / Log[2]
$\endgroup$
3
  • $\begingroup$ This is generally correct? $\endgroup$ Commented Feb 6, 2018 at 6:19
  • $\begingroup$ @AimForClarity, not sure. $\endgroup$
    – kglr
    Commented Feb 6, 2018 at 6:38
  • $\begingroup$ @Aim, yes. You can show this through the contour integral definition in my answer. $\endgroup$ Commented May 2, 2020 at 15:42
8
$\begingroup$

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().

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.

$\endgroup$
3
  • $\begingroup$ Nice! Thanks for the background material! $\endgroup$
    – sebhofer
    Commented Aug 25, 2015 at 14:03
  • 2
    $\begingroup$ Eight years ago I implemented the integration algorithms described in referenced article by N. Higham. If that is of interest I can post the implementations. And yes -- the more specialized numerical integration algorithm for MatrixLog is faster and more precise than the one for MatrixFunction. $\endgroup$ Commented Oct 9, 2015 at 13:29
  • $\begingroup$ I'd definitely be interested in seeing them! But, I'd thought MatrixLog[] would use something like inverse scaling + squaring internally; guess not. $\endgroup$ Commented Oct 9, 2015 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.