Ask Your Question
1

n-th power of matrices

asked 2016-10-16 10:56:39 +0100

iris gravatar image

updated 2023-05-19 14:33:14 +0100

FrédéricC gravatar image

Is there any way to calculate the n-th power of a (upper unitriangular) matrix in Sage? Here n is an integer variable.

For example, if y=matrix([[1,0,0],[0,1,1],[0,0,1]]), then I want to obtain a formula in n for y^n. In this case this would be y^n=matrix([[1,0,0],[0,1,n],[0,0,1]]).

I tried the following: sage: y=matrix([[1,0,0],[0,1,1],[0,0,1]]); var('n'); sage: y^n

This resulted in the error: "NotImplementedError: non-integral exponents not supported"

Adding sage: assume(n, 'integer') has no effect at all.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
1

answered 2016-10-16 22:39:14 +0100

castor gravatar image

updated 2016-10-16 23:00:57 +0100

You can find an interactive Sage application here: http://shrek.unideb.hu/~tengely/Magya... the last part is "Mátrixok n-edik hatványának zárt alakja", it is in Hungarian, but the mathematics and Sage command will help I think. In case of your example this code will not work, the eigenvalue 1 has multiplicity larger than 1. To make it work the computation related to the eigenvectors should be modified. At the above page the matrix is given by matrix([[1,2,1],[6,-1,0],[-1,-2,-1]]) and after pushing the "Számolás" button you see the general form of the $n$th power of this matrix. If you have a diagonalizable matrix the above code should do the job.

edit flag offensive delete link more
1

answered 2018-04-02 23:40:14 +0100

slelievre gravatar image

This was asked again in Ask Sage question 35658, and an initial implementation was proposed as an answer to that question, and included in SageMath at Sage Trac ticket 22523.

A bug was reported in Ask Sage question 41622 and a fix for this bug was provided as an answer to that question and is ready for inclusion in SageMath at Sage Trac ticket 25082.

This makes it possible to compute the matrix power in the question here.

sage: n = SR.var('n')
sage: y = matrix([[1, 0, 0], [0, 1, 1], [0, 0, 1]]); y
[1 0 0]
[0 1 1]
[0 0 1]
sage: z = y^n; z
[1 0 0]
[0 1 n]
[0 0 1]

Then one can substitute for particular values:

sage: z.subs({n: 5})
[1 0 0]
[0 1 5]
[0 0 1]
sage: y^5
[1 0 0]
[0 1 5]
[0 0 1]
edit flag offensive delete link more
0

answered 2016-10-16 14:29:37 +0100

tmonteil gravatar image

updated 2016-10-16 14:34:03 +0100

Unless i misunderstand you question, if M is your matrix and n is an integer, you can just do:

sage: M^n

or, if you prefer to be Python compatible:

sage: M**n
edit flag offensive delete link more

Comments

Thank you for answering. However, I think you misinterpreted my question. To be clear, in my question n is a variable (as stated), while the matrix I want to calculate the n-th power of is known. I reformulated my question.

iris gravatar imageiris ( 2016-10-16 16:27:01 +0100 )edit

I see. The name variable could be misleading, since it can stand for a Python name, a polynomial indeterminate or a symbol. Thanks for having made your question more precise.

tmonteil gravatar imagetmonteil ( 2016-10-16 19:00:21 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2016-10-16 10:56:39 +0100

Seen: 2,152 times

Last updated: Apr 02 '18