Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
1

n-th power of matrices

asked 8 years ago

iris gravatar image

updated 1 year ago

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.

Preview: (hide)

3 Answers

Sort by » oldest newest most voted
1

answered 8 years ago

castor gravatar image

updated 8 years ago

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 nth power of this matrix. If you have a diagonalizable matrix the above code should do the job.

Preview: (hide)
link
1

answered 6 years ago

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]
Preview: (hide)
link
0

answered 8 years ago

tmonteil gravatar image

updated 8 years ago

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
Preview: (hide)
link

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 ( 8 years ago )

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 ( 8 years ago )

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: 8 years ago

Seen: 2,312 times

Last updated: Apr 02 '18