How to Compute Matrix Powers with Sage

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

Discussion Overview

The discussion revolves around computing matrix powers using Sage, specifically focusing on a non-square matrix and the implications of that for calculations. Participants explore the requirements for matrix operations in Sage and the potential modifications needed to make the matrix square.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant presents a non-square matrix and asks how to compute its powers using Sage.
  • Another participant suggests that the matrix can be modified to be square but expresses uncertainty about the best approach to take.
  • There is confusion about the term "SAGE," with one participant questioning its relevance and another clarifying it as a software package for symbolic and numerical computations.
  • A participant mentions that the original question specifies using Sage, emphasizing the importance of addressing the matrix's square nature.
  • One participant shares their experience of modifying the matrix to a square form and provides results from Sage, noting that the original non-square matrix leads to an error when attempting to compute its powers.
  • Another participant confirms that the original matrix should be a 5x5 matrix, indicating a potential misunderstanding in the initial problem statement.

Areas of Agreement / Disagreement

Participants generally agree that the matrix needs to be square for powers to be computed in Sage. However, there is disagreement on how to modify the original matrix and whether the modifications still address the original question.

Contextual Notes

There are unresolved assumptions regarding the nature of the original matrix and its intended application, as well as the specific modifications that would be appropriate to make it square.

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