Processing math: 100%
Ask Your Question
1

Condensing variables of a matrix

asked 9 years ago

Iceman gravatar image

I'm working with matrices such as

M = matrix([
    [a, b, 0], 
    [c, 0, d], 
    [0, e, 0]])

where a, b, c, d, and e are variables. Then I loop through some numbers for each of a, b, c, d, and e, looking at the eigenvalues of the resulting matrix. char(M)=x3ax2(bc+de)x+ade So, I'm doing more work than necessary, and ideally, I'd reduce M down to

 M = matrix([
    [a, b, 0], 
    [1, 0, d], 
    [0, 1, 0]])

Is there a simple way of using Sage to do so?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
0

answered 9 years ago

tmonteil gravatar image

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

Comments

Maybe I should have been a little more explicit. I want a method for determining when a matrix can have the number of variables reduced. Implementing the reduction is the easy part.

Iceman gravatar imageIceman ( 9 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

1 follower

Stats

Asked: 9 years ago

Seen: 491 times

Last updated: Jul 08 '15