[sage-support] Re: solving matrix equations
Thanks to both of you! Mladen On Feb 7, 12:19 pm, Jason Grout wrote: > Craig Citro wrote: > > Hi, > > > Yep, there are definitely easy ways of doing this. Here's one way: > > > sage: var('a b c d') > > (a, b, c, d) > > sage: A = matrix(2,[2,1,1,1]) > > sage: B = matrix(2,[a,b,c,d]) > > sage: C = A*B - B*A > > > sage: [ e == 0 for e in C.list() ] > > [c - b == 0, d + b - a == 0, -d - c + a == 0, b - c == 0] > > > sage: solve([ e == 0 for e in C.list() ], N.list()) > > [[a == r2 + r1, b == r2, c == r2, d == r1]] > > Just to point out for those that need a guide through the above, Craig > is basically creating a list of equations from each entry in the matrix. > He doesn't show it, but I suppose that N is a matrix of the variables. > You could also do: > > solve([ e == 0 for e in C.list() ], C.variables()) > > That said, I think it would be a great thing if solve could recognize > matrices and that two matrices are equal if each entry is equal. I > believe MMA does this (but it's easier there; matrices are nothing more > than nested lists). It'd certainly make certain things I do more > natural if I could do: > > solve(matrixA==matrixB) > > and that was equivalent to: > > solve([i==j for i,j in zip(matrixA.list(), matrixB.list())]) > > if the matrices were of the same dimensions. > > Okay, so now that I've written my piece, I suppose the next step is to > open a trac ticket, write a patch to implement it, and post it for > review :). > > The ticket ishttp://trac.sagemath.org/sage_trac/ticket/5201 > > I won't cry if someone submits a patch before I get to it :). > > Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: solving matrix equations
Craig Citro wrote: > Hi, > > Yep, there are definitely easy ways of doing this. Here's one way: > > sage: var('a b c d') > (a, b, c, d) > sage: A = matrix(2,[2,1,1,1]) > sage: B = matrix(2,[a,b,c,d]) > sage: C = A*B - B*A > > sage: [ e == 0 for e in C.list() ] > [c - b == 0, d + b - a == 0, -d - c + a == 0, b - c == 0] > > sage: solve([ e == 0 for e in C.list() ], N.list()) > [[a == r2 + r1, b == r2, c == r2, d == r1]] Just to point out for those that need a guide through the above, Craig is basically creating a list of equations from each entry in the matrix. He doesn't show it, but I suppose that N is a matrix of the variables. You could also do: solve([ e == 0 for e in C.list() ], C.variables()) That said, I think it would be a great thing if solve could recognize matrices and that two matrices are equal if each entry is equal. I believe MMA does this (but it's easier there; matrices are nothing more than nested lists). It'd certainly make certain things I do more natural if I could do: solve(matrixA==matrixB) and that was equivalent to: solve([i==j for i,j in zip(matrixA.list(), matrixB.list())]) if the matrices were of the same dimensions. Okay, so now that I've written my piece, I suppose the next step is to open a trac ticket, write a patch to implement it, and post it for review :). The ticket is http://trac.sagemath.org/sage_trac/ticket/5201 I won't cry if someone submits a patch before I get to it :). Jason --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---
[sage-support] Re: solving matrix equations
Hi, Yep, there are definitely easy ways of doing this. Here's one way: sage: var('a b c d') (a, b, c, d) sage: A = matrix(2,[2,1,1,1]) sage: B = matrix(2,[a,b,c,d]) sage: C = A*B - B*A sage: [ e == 0 for e in C.list() ] [c - b == 0, d + b - a == 0, -d - c + a == 0, b - c == 0] sage: solve([ e == 0 for e in C.list() ], N.list()) [[a == r2 + r1, b == r2, c == r2, d == r1]] -cc On Sat, Feb 7, 2009 at 9:45 AM, mb wrote: > > Hi, > > Say I want to compute the centralizer of a matrix. > > sage: P.=PolynomialRing(QQ) > sage: A=matrix(P,2,2,[2,1,1,1]) > sage: B=matrix(P,2,2,[a,b,c,d]) > sage: C=A*B-B*A > sage: C > > [-b + c -a + b + d] > [ a - c - d b - c] > sage: var('a b c d') > (a, b, c, d) > sage: solve([-b + c==0,-a + b + d==0,a - c - d==0,b - c==0],[a,b,c,d]) > [[a == r2 + r1, b == r2, c == r2, d == r1]] > > Here I had to manually copy the entries of C into solve, which is a > problem for larger matrices. Ideally, something like > > solve(C==0,[a,b,c,d]) > > should work, but of course it doesn't. Is there any way of doing this? > > Mladen > > > --~--~-~--~~~---~--~~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~--~~~~--~~--~--~---