MHB How to Compute Matrix Powers with Sage

  • Thread starter Thread starter karush
  • Start date Start date
karush
Gold Member
MHB
Messages
3,240
Reaction score
5
$\textsf{Let:}$

$$ S=\left[\begin{array}{rrrrrr}
0& 1& 0& 0&0\\ 0& 0& 1& 0&0\\ 0& 0& 0&1&0\\0&0&0&0&0
\end{array}\right]$$

$Compute \, S^k k=2,...,6$

$\text{ok we are supposed to do this with SAGE}$

$\text{but not sure how $S^k$ is applied}$

i had this on another forum but just said it wasn't square
but i think S can be modified
 
Physics news on Phys.org
karush said:
i had this on another forum but just said it wasn't square
but i think S can be modified

You are probably right, you can make it square, but this can be done in many ways and it is not clear to me which one to choose.
Does this matrix come from some application problem and could you deduce from there what modification would be most appropriate?
 
The "other Forum" had a simple question that never got answered as far as I know.

What the (Swearing) is "SAGE?"

-Dan
 
topsquark said:
What the (Swearing) is "SAGE?"
In the UK, it is the leading supplier of accounting software packages for small businesses, https://uk.sageone.com/accounts/.

I would not recommend it as a platform for linear algebra. (Fubar)
 
Sage is a combination of various symbolic and numerical packages under open source licenses.
I never used it myself, although I did use some of its components.

I don't think this matters too much for the original question.
 
Last edited:
The original post specifically said that this problem was to be solved "using SAGE". That is why it is "important" here.

Karush, I was the one who told you that we cannot find powers of that matrix because it is not square. I imagine there are many ways S can be "modified" to be square but then you no longer have "S" and are not answering the question asked! It may be that you mis-copied the problem. Please check that.
 
Ok. I was curious now.
I've heard about SageMath before as a free open source alternative to Mathematica and Maple, which are both expensive.
... so I installed it, and tried it out...

Since we need a square matrix for S, I've made it a 4x4 matrix, which seems reasonable, because that makes it a standard nilpotent matrix.
Executing it in sage gives us:
Code:
sage: S=Matrix([[0,1,0,0],[0,0,1,0],[0,0,0,1],[0,0,0,0]])
sage: for k in range(5):
...:     S^(k+2)
...:     

[0 0 1 0]
[0 0 0 1]
[0 0 0 0]
[0 0 0 0]

[0 0 0 1]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]

[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]

[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]

[0 0 0 0]
[0 0 0 0]
[0 0 0 0]
[0 0 0 0]

And if I try it with the matrix in the OP, we get:
Code:
sage: S=Matrix([[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,0]])
sage: for k in range(5):
...:     S^(k+2)
...:     
---------------------------------------------------------------------------
ArithmeticError                           Traceback (most recent call last)
<ipython-input-38-5b09aa8b46ef> in <module>()
      1 for k in range(Integer(5)):
----> 2     S**(k+Integer(2))
      3 

sage/matrix/matrix_integer_dense.pyx in sage.matrix.matrix_integer_dense.Matrix_integer_dense.__pow__ (/usr/lib/sagemath//src/build/cythonized/sage/matrix/matrix_integer_dense.c:11582)()

ArithmeticError: self must be a square matrix
 
yeah the op was supposed be a 5x5

I never tried mathamatica or the other exotic programs but sage looks good to me

I have some more probs to post
 

Similar threads

Replies
7
Views
2K
Replies
19
Views
3K
Replies
5
Views
2K
Replies
2
Views
984
Replies
3
Views
1K
Back
Top