>
> How can i compute the matrix multiplication (product) of two symbolic
> matrices in sage ?
I'm not an expert in this part of Sage, but I think you need to get
more explicit about what you are doing. Real experts can correct me
where I err.
In Sage, there is a "symbolic ring" that supports all symbolic
computation. When you declare variables:
sage: var('x y z w')
(x, y, z, w)
these elements belong to that ring:
sage: x.parent()
Symbolic Ring
The name of the ring is 'SR':
sage: SR
Symbolic Ring
This seems to give you what you want:
sage: M = Matrix(SR,2,2,[x,y,z,w])
sage: M
[x y]
[z w]
sage: M*M
[y*z + x^2 x*y + w*y]
[x*z + w*z y*z + w^2]
sage: M^-1
[ w/(w*x - y*z) -y/(w*x - y*z)]
[-z/(w*x - y*z) x/(w*x - y*z)]
HTH,
Justin
--
Justin C. Walker, Curmudgeon at Large
Director
Institute for the Enhancement of the Director's income
-----------
--
They said it couldn't be done, but sometimes,
it doesn't work out that way.
- Casey Stengel
--
> On Sun, Mar 8, 2009 at 1:43 PM, alex
> <alessandro.be...@gmail.com> wrote:
>>
>> How can i compute the matrix multiplication (product) of two symbolic
>> matrices in sage ?
>>
>> I have tried:
>> A = maxima("matrix ([a, b], [c, d])")
>> AI= A.invert()
>>
>> and
>> A * AI
>> gives
>> matrix([a*d/(a*d-b*c),-b^2/(a*d-b*c)],[-c^2/(a*d-b*c),a*d/(a*d-b*c)])
>
>
> Do you want the following?
>
> sage: a,b,c,d = var("a,b,c,d")
> sage: A = matrix ([[a, b], [c, d]])
> sage: AI = A.inverse()
> sage: P = A*AI; P
>
> [a*d/(a*d - b*c) - b*c/(a*d - b*c) 0]
> [ 0 a*d/(a*d - b*c) - b*c/(a*d - b*c)]
sage: P.simplify_rational()
[1 0]
[0 1]
It's probably because no one has written it yet. I think it'd be great
to have. We welcome any patches to do that.
You can do the same thing using the apply_map function, which applies a
function to each entry of a matrix.
sage: var('a,b,c,d')
(a, b, c, d)
sage: A=matrix([[sin(a+b), sin(c+d)],[cos(a+d),cos(b+d)]])
sage: A
[sin(b + a) sin(d + c)]
[cos(d + a) cos(d + b)]
sage: B=A.apply_map(lambda x: x.full_simplify())
sage: B
[cos(a)*sin(b) + sin(a)*cos(b) cos(c)*sin(d) + sin(c)*cos(d)]
[cos(a)*cos(d) - sin(a)*sin(d) cos(b)*cos(d) - sin(b)*sin(d)]
Jason
There should be a matrix exponential function:
sage: var('a,b,c,d')
(a, b, c, d)
sage: A=matrix([[a,0],[0,d]])
sage: A.exp()
[e^a 0]
[ 0 e^d]
sage: A=matrix([[a,2],[0,d]])
sage: A.exp()
[ e^a (2*e^d - 2*e^a)/(d - a)]
[ 0 e^d]
Jason