EDIT #2
The regularization method is more generally applicable than the Cauchy method.
Here's an example for which (according to J.M.) the Cauchy method fails but the regularization method works.
The matrix is that of the OP (integer form)
matx = {{1, -3, -2}, {-1, 3, -2}, {0, 0, 0}};
Eigenvalues[matx]
(* Out[90]= {4, 0, 0} *)
and the function has an essential singularity at 0. We obatin immediately
Limit[MatrixFunction[1/# Exp[-1/#] &, matx + \[Epsilon] IdentityMatrix[3]], \[Epsilon] -> 0] // FullSimplify
(* Out[50]= {{1/(16 E^(1/4)), -(3/(16 E^(1/4))), 1/(16 E^(1/4))}, {-(1/(16 E^(1/4))), 3/(16 E^(1/4)), -(1/(16 E^(1/4)))}, {0, 0, 0}} *)
Really simple, and fast.
EDIT
J.M.'s example treated with the regularization method
The Matrix:
rm = {{2/3, 0, -(2/3), -(1/3)}, {0, 1, 0, 0}, {1/3, 0, 2/3, -(2/3)}, {2/3, 0, 1/3, 2/3}}
The task is to calculate the matrix function
MatrixFunction[Log[#]/(# - 1) &, rm]
During evaluation of In[29]:= MatrixFunction::fnand: The function Log[#1]/(#1-1)& is not analytic or defined at 1. >>
The direct approach fails.
But regularization makes life easy:
MatrixFunction[Log[#]/(# - 1) &,
rm + \[Epsilon] IdentityMatrix[4]];
Limit[%, \[Epsilon] -> 0] // FullSimplify
(* Out[33]= {{1/9 (3 + Sqrt[3] \[Pi]), 0, 1/9 (-3 + Sqrt[3] \[Pi]), 1/
3}, {0, 1, 0, 0}, {-(1/3), 0, 1/9 (3 + Sqrt[3] \[Pi]),
1/9 (-3 + Sqrt[3] \[Pi])}, {1/9 (3 - Sqrt[3] \[Pi]), 0, -(1/3),
1/9 (3 + Sqrt[3] \[Pi])}} *)
Summary
It may seem that the problem comes from the singularity of the Matrix mat
, and is naturally related to the problem with Sin[x]/x/.x->0
. But J.M. showed that problems arise if the matrix is defective.
There is no problem with MatrixFunction[Sinc, mat1]
if Det[mat1] != 0
.
We shall proceed here without exploring the root cause and show that the MatrixFunction
of the OP can be computed exactly using two methods (a) power series, and (b) regularization, with the result:
MatrixFunction[Sinc, mat] ==
$$\begin{pmatrix}
\frac{1}{16} (\sin (4)+12) & \frac{1}{16} (-3) (\sin (4)-4) & \frac{1}{16} (\sin (4)-4) \\
\frac{1}{16} (4-\sin (4)) & \frac{1}{16} (3 \sin (4)+4) & \frac{1}{16} (4-\sin (4)) \\
0 & 0 & 1 \\
\end{pmatrix}$$
Derivation
Power series
We shall calculate the matrix function by a power series. This requires nothing but the powers of the matrix which always exist for a square matrix.
Here is the power series of Sinc[]
:
Sum[(-1)^k x^(2 k)/(2 k + 1)!, {k, 0, ∞}]
(* Out[10]= Sin[x]/x *)
The matrix in question is
mat = {{1., -3, -2}, {-1, 3, -2}, {0.`, 0.`, 0.`}}
(* Out[9]= {{1., -3, -2}, {-1, 3, -2}, {0., 0., 0.}} *)
In order to calculate the powers symbolically we take numerical constants and define
mat1 = Floor[mat]
(* Out[11]= {{1, -3, -2}, {-1, 3, -2}, {0, 0, 0}} *)
From the first few even powers we can easily guess the general form:
mp[k_] := {{4^(2 k - 1), -3 4^(2 k - 1), 4^(2 k - 1)}, {-4^(2 k - 1),
3 4^(2 k - 1), -4^(2 k - 1)}, {0, 0, 0}};
Notice that, due to the singularity of mat1, the zeroth power does not exist.
MatrixPower[mat1, 0]
During evaluation of In[15]:= MatrixPower::sing: Matrix
{{1,-3,-2},{-1,3,-2},{0,0,0}} is singular. >>
(* Out[15]= MatrixPower[{{1, -3, -2}, {-1, 3, -2}, {0, 0, 0}}, 0] *)
Hence we take care of the zeroth power by simply adding the unit matrix.
We find finally
f = DiagonalMatrix[Array[1 &, 3]] +
Sum[(-1)^k mp[k]/(2 k + 1)!, {k, 1, ∞}]
(* Out[46]= {{1 + 1/16 (-4 + Sin[4]), -(3/16) (-4 + Sin[4]),
1/16 (-4 + Sin[4])}, {1/16 (4 - Sin[4]), 1 + 3/16 (-4 + Sin[4]),
1/16 (4 - Sin[4])}, {0, 0, 1}} *)
Regularization
If we make the matrix into a regular one by adding a small matrix
mat2 = mat1 + ε DiagonalMatrix[Array[1 &, 3]];
Det[mat2]
(* Out[48]= ε (4 ε + ε^2) *)
we can apply the MatrixFunction without any problem:
f2 = MatrixFunction[Sinc, mat2];
and then take the limit
f20 = Limit[f2, ε -> 0];
This gives the same result as before
f == f20
(* Out[52]= True *)
Numerical matrix, partial series
Defining the partial series as
fn[nn_] :=
DiagonalMatrix[Array[1 &, 3]] +
Sum[(-1)^k MatrixPower[mat, 2 k]/(2 k + 1)!, {k, 1, nn}]
we can calculate the numerical result up to the nn-th term.
For nn = 8
the result is alrady we find
fn[8] // N
(* Out[64]= {{0.7027, 0.8919, -0.2973}, {0.2973, 0.1081, 0.2973}, {0., 0., 1.}} *)
in fair agreement with the exact values:
f // N
(* Out[65]= {{0.7027, 0.8919, -0.2973}, {0.2973, 0.1081, 0.2973}, {0., 0., 1.}} *)
Numerical matrix, regularization
Regularizing the numerical matrix of the OP gives
mat4 = mat + ε DiagonalMatrix[Array[1 &, 3]];
Application of MatrixFunction
with given small ε
f4 = MatrixFunction[Sinc, mat4] /. ε -> 10^(-8)
During evaluation of In[96]:= JordanDecomposition::jdimp: Unable to
find the Jordan decomposition of the matrix with the given precision.
Try higher precision or SchurDecomposition instead. >>
(* Out[96]= {{0.7027, 0.8919, -0.2973}, {0.2973, 0.1081, 0.2973}, {0., 0., 1.}} *)
results in the known numerical result despite of the error message.
Examples of singular matrices
An extreme case of a matrix is
mat3 = {{0, 0}, {0, 0}};
Nevertheless, there's no problem with Sinc:
MatrixFunction[Sinc, mat3]
(* Out[73]= {{1, 0}, {0, 1}} *)
Matrices of the type {{a,b},{0,0}} with a,b [Element]{0,1}
mm = {#, {0, 0}} & /@ Union[Tuples[{1, 0, 0, 0}, 2]]
(* Out[15]= {{{0, 0}, {0, 0}}, {{0, 1}, {0, 0}}, {{1, 0}, {0, 0}}, {{1, 1}, {0, 0}}} *)
Table[{k, MatrixFunction[Sinc, mm[[k]]]}, {k, 1, 4}]
During evaluation of In[18]:= MatrixFunction::fnanc: The function Sinc[#1]& is not analytic at 0. >>
(* Out[18]= {
{1, {{1, 0}, {0, 1}}},
{2, MatrixFunction[inc, {{0, 1}, {0, 0}}]},
{3, {{Sinc[1], 0}, {0, 1}}},
{4, {{Sinc[1], -1 + Sinc[1]}, {0, 1}}}
} *)
Notice that only for mm[[2]] Mathematica complains the presumed non-analyticity of Sinc at 0 and Returns the input unevaluated.
Again the regularization method removes the problem:
meps = \[Epsilon] IdentityMatrix[2];
Table[{k, MatrixFunction[Sinc, meps + mm[[k]]]}, {k, 1, 4}];
Limit[%, \[Epsilon] -> 0]
(* Out[21]= {{1, {{1, 0}, {0, 1}}}, {2, {{1, 0}, {0, 1}}}, {3, {{Sin[1], 0}, {0, 1}}}, {4, {{Sin[1], -1 + Sin[1]}, {0, 1}}}} *)
Sinc'[0.]
andSinc'[x]
give a clue? (The derivative ofSinc
unfortunately reverts to the derivative ofSin[x]/x
.) $\endgroup$MatrixFunction
requires the derivatives, and not "just" the sum of the ponderated matrix powers? $\endgroup$wkm
can be used to computesinc(A)
as follows: A = [1, -3, -2; -1, 3, -2; 0, 0, 0]; [C, S] = wkm(-A^2); The matricesC
andS
returned bywkm
are the matrix functionscos(A)
andsinc(A)
. $\endgroup$