How to Compute Matrix Powers with Sage

  • Context: MHB 
  • Thread starter Thread starter karush
  • Start date Start date
Click For Summary
SUMMARY

The discussion focuses on computing matrix powers using SageMath, specifically for a nilpotent matrix. The original matrix provided was a 5x5 non-square matrix, which led to confusion regarding its modification to a square form. Participants concluded that the matrix must be square to compute its powers, and a 4x4 version was successfully used to demonstrate the computation of powers from k=2 to k=6. SageMath is identified as a suitable open-source alternative for linear algebra tasks.

PREREQUISITES
  • Understanding of matrix operations, specifically matrix exponentiation.
  • Familiarity with SageMath for symbolic and numerical computations.
  • Knowledge of nilpotent matrices and their properties.
  • Basic programming skills in Python, as SageMath uses Python syntax.
NEXT STEPS
  • Learn how to install and set up SageMath for matrix computations.
  • Explore the properties of nilpotent matrices and their applications in linear algebra.
  • Research matrix exponentiation techniques in SageMath, including the use of loops and functions.
  • Investigate other open-source alternatives to SageMath for linear algebra, such as NumPy or SciPy.
USEFUL FOR

Mathematicians, educators, and students involved in linear algebra, particularly those interested in using SageMath for matrix computations and exploring nilpotent matrices.

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 4 ·
Replies
4
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 19 ·
Replies
19
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 15 ·
Replies
15
Views
3K
  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K