Can't get Sage to simplify a matrix with square root of numbers inside

145 views
Skip to first unread message

galileon

unread,
Feb 16, 2009, 10:57:43 AM2/16/09
to sage-support
Dear all,
I diagonalized a given 3x3 matrix, ie found the eigenvalues and
eigenvectors, manually. I wanted to check my answer with Sage:
M = matrix([[8,-3,-3],[-3,8,-3],[-3,-3,8]])
show(M)
O = matrix([[1/sqrt(3),1/sqrt(2),1/sqrt(6)],[1/sqrt(3),-1/sqrt(2),1/
sqrt(6)],[1/sqrt(3),0,-2/sqrt(6)]])
OT = O.transpose()
show(O)
show(OT)
show(OT * O)
diag = matrix([[2,0,0],[0,11,0],[0,0,11]])
show(diag)
show(O * diag * OT)
show(OT * M * O)

M is my given matrix, O is a matrix with the eigenvectors as columns,
and OT is the transpose of O.
show(OT*O) works as expected, and gives the unit matrix. When I show
(OT * M * O), however, the first and third rows are as expected
([2,0,0] and [0,0,11], it the eigenvalues, as in the matrix diag). The
second line is a bit wierd though. I get something that should
evaluate to [zero,11,zero], but it is not being displayed as such.
Instead, there are plenty of square roots in it, and Sage is not
simplifying it. I've posted the picture here http://galileon.co.uk/matrix.png.

x=OT*M*O
x.simplify()
show(x)

did not help either.
version() gives 'Sage Version 3.2.2, Release Date: 2008-12-18', its a
binary distribution.

uname -a gives:
Linux carybdis 2.6.27-11-generic #1 SMP Thu Jan 29 19:24:39 UTC 2009
i686 GNU/Linux
UBUNTU 8.10

Any ideas? Thanks :)

Jason Grout

unread,
Feb 16, 2009, 3:56:28 PM2/16/09
to sage-s...@googlegroups.com


You're right, the problem is that Sage isn't simplifying it:

The following code applies the simplify_full() method to each entry of
OT*M*O

sage: D=OT*M*O
sage: D.apply_map(lambda x: x.simplify_full())

[ 2 0 0]
[ 0 11 0]
[ 0 0 11]


Jason

galileon

unread,
Feb 17, 2009, 6:15:20 AM2/17/09
to sage-support
Awesome! Thank you very much Sir! I'll give it a try when I get home
tonight.
Cheers,
Nawal.
> > simplifying it. I've posted the picture herehttp://galileon.co.uk/matrix.png.

galileon

unread,
Feb 17, 2009, 2:14:49 PM2/17/09
to sage-support
That worked great, thanks! Here's the exact code I've used, if it may
help some noobie like myself someday:

M = matrix([[8,-3,-3],[-3,8,-3],[-3,-3,8]])
show(M)
O = matrix([[1/sqrt(3),1/sqrt(2),1/sqrt(6)],[1/sqrt(3),-1/sqrt(2),1/
sqrt(6)],[1/sqrt(3),0,-2/sqrt(6)]])
OT = O.transpose()
show(O)
show(OT)
show(OT * O)
diag = matrix([[2,0,0],[0,11,0],[0,0,11]])
show(diag)
D=OT * M * O
show(D)
f = D.apply_map(lambda x: x.simplify_full())
show(f)

The important thing I noticed is that D.apply_map() doesn't update D
itself, but must be assigned to a new variable.


Thanks,

Nawal.

Jason Grout

unread,
Feb 17, 2009, 2:47:43 PM2/17/09
to sage-s...@googlegroups.com
galileon wrote:

>
> That worked great, thanks! Here's the exact code I've used, if it may
> help some noobie like myself someday:
>
> M = matrix([[8,-3,-3],[-3,8,-3],[-3,-3,8]])
> show(M)
> O = matrix([[1/sqrt(3),1/sqrt(2),1/sqrt(6)],[1/sqrt(3),-1/sqrt(2),1/
> sqrt(6)],[1/sqrt(3),0,-2/sqrt(6)]])
> OT = O.transpose()
> show(O)
> show(OT)
> show(OT * O)
> diag = matrix([[2,0,0],[0,11,0],[0,0,11]])
> show(diag)
> D=OT * M * O
> show(D)
> f = D.apply_map(lambda x: x.simplify_full())
> show(f)
>
> The important thing I noticed is that D.apply_map() doesn't update D
> itself, but must be assigned to a new variable.
>

Yes, or you could assign it to D again:

D = D.apply_map(lambda x: x.simplify_full())


Jason

Reply all
Reply to author
Forward
0 new messages