0
$\begingroup$

I ran this and got some errors. Does anyone know how to solve this? First I want to caluclate A^2(A+I) with A = {{0, 1, 0}, {0, 0, 0}, {0, 0, -1}}.

MatrixFunction[#^2.(# + IdentityMatrix[3]) &, {{0, 1, 0}, {0, 0,
0}, {0, 0, -1}}]

StringForm::sfr: Item 1 requested in "Cannot compute the matrix function for the function 1." out of range; 0 items available. MatrixFunction::nosol: Cannot compute the matrix function for the function 1.

Second, I want to calculate A2^k:

A2= {{-0.5, 3}, {0, -0.8}};
MatrixFunction[#^k &, A2] // 
  FullSimplify[#, k > 0 && k \[Element] Integers] & // MatrixForm

MatrixFunction::fnnum: Unable to compute the matrix function because the function #1^k& at a numeric value is not numeric.

$\endgroup$
4
  • 2
    $\begingroup$ I'm not sure what you're trying to do. $\endgroup$
    – chuy
    May 11, 2021 at 19:35
  • $\begingroup$ You can't have a matrix in the pure function in the first example. Use MatrixPower instead for the second example. $\endgroup$
    – Carl Woll
    May 11, 2021 at 20:37
  • $\begingroup$ @chuy I updated the post $\endgroup$
    – emnha
    May 12, 2021 at 5:28
  • $\begingroup$ @CarlWoll I want to make a pure function #^2(#+I) where I is the identiy matrix. So how can I make that? $\endgroup$
    – emnha
    May 12, 2021 at 5:29

1 Answer 1

2
$\begingroup$
A = RandomReal[{0, 1}, {3, 3}];
MatrixFunction[#^2 (# + 1) &, A] == A . A . (A + IdentityMatrix[3])
(*    True    *)

You need to use the number 1, not the unit matrix, in the definition of the function for MatrixFunction. As the documentation states,

For convergent power series, MatrixFunction[f,m] effectively evaluates the power series for the function f with ordinary powers replaced by matrix powers.

For the second case, as @CarlWoll says, use MatrixPower:

A2 = {{-0.5, 3}, {0, -0.8}};
MatrixPower[A2, k]
(*    {{0. + 1. (-0.5)^k, -10. (-0.8)^k + 10. (-0.5)^k},
       {0.,               0. + 1. (-0.8)^k}}                *)

For some reason, MatrixFunction[#^k &, A2] does not seem to work if k is unspecified, even though the exact calculation works without a problem:

A2 = {{-1/2, 3}, {0, -4/5}};
MatrixFunction[#^k &, A2]
(*    {{(-1/2)^k, 5 (-1)^k 2^(1 - k) + (-1)^(1 + k) 2^(1 + 2 k) 5^(1 - k)},
       {0,        (-4/5)^k}}                                                   *)
$\endgroup$
4
  • $\begingroup$ This would be complete if why ` MatrixFunction[#^k &, A2]` does not work is answered. $\endgroup$
    – emnha
    May 14, 2021 at 4:30
  • $\begingroup$ @anhnha see update $\endgroup$
    – Roman
    May 14, 2021 at 7:30
  • $\begingroup$ could you add the why the exact numbers make it work? $\endgroup$
    – emnha
    May 14, 2021 at 7:41
  • 1
    $\begingroup$ If I knew, I would have. $\endgroup$
    – Roman
    May 14, 2021 at 8:14

Your Answer

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

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