ASKSAGE: Sage Q&A Forum - Latest question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 16 Oct 2016 03:56:39 -0500n-th power of matriceshttp://ask.sagemath.org/question/35155/n-th-power-of-matrices/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.irisSun, 16 Oct 2016 03:56:39 -0500http://ask.sagemath.org/question/35155/How to robustly simplify an object (including a number)http://ask.sagemath.org/question/8576/how-to-robustly-simplify-an-object-including-a-number/Hi,
When writing a package, I met the following problem:
Say, I want the variable 'a' to be an expression, which is passed to the package by user. Then I want to call a.simplify() to simplify the expression.
However, as an input, a could naturally be the following cases:
# case 1
a = var('t')
# case 2
a = 1
# case 3
a = 0.1
a.simplify() will work on 1, but not work on 2 or 3, which crashes the whole package.
I could do something as
try:
b = a.simplify()
except:
b = a
But this really seems like a workaround instead of something formal. Is there a better way to handle this case? Thanks!
tririverMon, 19 Dec 2011 02:14:40 -0600http://ask.sagemath.org/question/8576/