1 | initial version |
You can define a function my_matrix
, which transforms Python variables to your matrix:
sage: my_matrix = lambda a,b,c,d,e : matrix([[a, b, 0], [c, 0, d], [0, e, 0]])
sage: my_matrix(pi,0,1,1/2,42)
[ pi 0 0]
[ 1 0 1/2]
[ 0 42 0]
Then you can do something like
sage: var('a,b,c,d,e') # those letters are symbols (like undeterminates), not Python variables.
(a, b, c, d, e)
sage: my_matrix(a,b,1,d,1)
[a b 0]
[1 0 d]
[0 1 0]
sage: my_matrix(a,b,1,d,1).charpoly()
x^3 - a*x^2 + (-b - d)*x + a*d
sage: my_matrix(a,a,a,a,a)
[a a 0]
[a 0 a]
[0 a 0]