Logarithm of a matrix, with a matrix as the base: Find $x$ in $\mathbf{A}^x = \mathbf{B}$

It is not clear what you mean by $A^x$ for $x$ irrational or even for $x$ not an integer. This is an issue already when $n = 1$; for example, what do you mean by $(-1)^{1/2}$? ( Which square root of $-1$?) What do you mean by $(-1)^{\pi}$?

One fix in the case $n = 1$ is to restrict to the case that $A, B$ are positive reals. The corresponding restriction for matrices is to restrict to the case that $A, B$ are positive-definite Hermitian matrices. In that case the spectral theorem guarantees that $A$ has an orthonormal basis of eigenvectors $e_1, ... e_n$ with positive real eigenvalues $\lambda_1, ... \lambda_n$, so you can define $A^x$ by requiring that $$A^x e_i = \lambda_i^x e_i$$

for all $i$. A necessary condition for the existence of a solution to $A^x = B$ is that $B$ also has eigenvectors $e_1, ... e_n$ (since this is true of $A^x$), and a necessary and sufficient condition is that its eigenvalues $\mu_1, ... \mu_n$ with respect to those eigenvectors satisfies $$\lambda_i^x = \mu_i$$

for all $i$.


Let's start with a random matrix $A$:

A = round(10*rand(2))
A = 
 2   6
 7   9

The following matrix $B$ is the cube of $A$:

B=A^3
B =
 554    870
1015   1569

How would you find the exponent with which we raised $A$? In this case it was 3. Let's see if we can find it in a systematic say.

We start by verifying that $B$ is indeed a power of $A$, by verifying that the eigenvectors are the same:

[AE AD]=eig(A);AE
AE =

  -0.8406  -0.4834
   0.5416  -0.8754

[BE BD]=eig(B);BE
BE =

  -0.8406  -0.4834
   0.5416  -0.8754

We now just have to find the exponent $x$ such that the eigenvalues $\lambda_{A,i}$ of $A$ and $\lambda_{B,i}$ of $B$ are related by:

$$\tag{1} \left(\lambda_{A,i}\right)^x = \lambda_{B,i}. $$

Unfortunately in this case we have:

$$\tag{2} \left(\lambda_{A,1}\right)^3 = \lambda_{B,1} < 0, $$

so it might not be the best idea to try to use logarithms immediately to obtain the exponent 3 (we would like to try to avoid calculating the log of a negative number!), but by applying the absolute value first and using the change of base formula we get:

diag(log(abs(BD))./log(abs(AD)))
ans =
 3.0000
 3.0000

This tells us that the solution to $A^x = B$ in this case is $x=3$.

In general, for matrices $A$ and $B$ with shared eigenvector matrices $U$, we can define $\log_A(B)$ as:

$$\tag{3} UDU^{-1} $$

where as long as no eigenvalues were 0, we have:

$$ D = \begin{pmatrix} \frac{\ln|\lambda_{B,1}|}{\ln|\lambda_{A,1}|} & 0& 0 & \cdots & 0\\ 0 & \frac{\ln|\lambda_{B,2}|}{\ln|\lambda_{A,2}|} & 0& \cdots & 0\\ 0 & 0 & \ddots & \cdots & 0\\ \vdots & \vdots & \ddots & \cdots & 0\\ 0 & 0 & 0 & 0 & \frac{\ln|\lambda_{B,n}|}{\ln|\lambda_{A,n}|}\\ \end{pmatrix} $$

If $B$ is truly a power of $A$, then this power will be the value on each diagonal of the matrix $\log_A(B)$. The following sequence of commands will get you there (notice that the diagonals in the final answer are both 3):

A = round(10*rand(2));B=A^3;
[AE AD]=eig(A);[BE BD]=eig(B);
X=AE*diag(diag(log(abs(BD))./log(abs(AD))))*inv(AE) 
X =
 3.0000e+00   1.2304e-13
 1.2301e-13   3.0000e+00

If you want to bring the off-diagonals closer to 0 (they'll never be exactly 0 if you're using floating-point arithmetic), you can multiply by $U^{-1}$ on the left and $U$ on the right:

inv(AE)*AE*diag(diag(log(abs(BD))./log(abs(AD))))*inv(AE)*AE
ans =
 3.0000e+00   2.8477e-16
 2.4057e-17   3.0000e+00

But the amazing thing about what we just did, is that if you then calculate $A^X = e^{\ln(A)X}$, you actually get back $B$! Perhaps even more amazingly, this even works when $A$ has a negative eigenvalue and no absolute value functions are included in the definition for calculating the matrix $X$ (though the direct interpretation as an exponent is lost).

There's also other ways to define functions of matrices, for example

  • by Sylvester's formula
  • by Taylor expansion (in this case expand $\log_A(B)$ around $A=C$ as long as $C$ has non-negative eigenvalues and is not a matrix of ones?),
  • by a Laurent series when a Taylor series doesn't work,
  • by a Pade approximant,
  • etc.

See also the Wikipedia atricle on analytic functions of matrices.