How to factor a expressions in a matrix with mathematica 7?

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 6K views
andresordonez
Messages
65
Reaction score
0
Hi, is there a way to factor expressions in matrices? for example

In[1]:= MatrixSimplify[{{3/2, 5/2}, {9/2, 1/2}}] (*I just made up the name MatrixSimplify*)

Out[1]:= 1/2 * {{3, 5}, {9, 1}}

I tried with Simplify[] and with Factor[] but it didn't work, it seems they just simplify every element in the matrix but not the matrix as a whole.

Thanks.
 
Physics news on Phys.org
Mathematica's method of evaluating how simple an expression is determines that {{3/2, 5/2}, {9/2, 1/2}} is simpler than 1/2 * {{3, 5}, {9, 1}} and so it will automatically force it back to your undesired form even if you find a way to extract the denominator. Try entering your "simplified" form to confirm this.

Perhaps you can see a way to use this to accomplish what you wish

In[1]:= m = {{3/2, 5/2}, {9/2, 1/2}};c = Apply[LCM, Map[Denominator, Flatten[m]]];{1/c, c*m}

Out[1]= {1/2,{{3, 5}, {9, 1}}}
 
Thanks, that's an interesting way to solve it, I wasn't familiar with the use of Apply and Map.

I wonder why mathematica "thinks" that {{3/2, 5/2}, {9/2, 1/2}} is simpler than 1/2 * {{3, 5}, {9, 1}}. (It's a shame that mathematica is not open source, that's so unscientific)
 
There are two, sometimes contradictory, things going.

In[6]:=LeafCount[{{3/2,5/2},{9/2,1/2}}]
Out[6]=15
In[7]:=LeafCount[{{3,5},{9,1}}]
Out[7]=7
and so, if it didn't do the multiply, 1/2*m would have a LeafCcount of 11, less than 15 and thus seemingly "simpler."

The other is that operations on numeric values are automatically carried out.

In your example the second one wins.

It is possible to block some automatic operations during display using HoldForm
In[8]:=HoldForm[1/2*{{3,5},{9,1}}]
but all the various Hold functions are a tricky tarpit to enter for most folks.

There are open source alternatives, Axiom, Sage and Maxima are three. But each of those represents 100 or 1000 man years of development and most things of that size are impossible for a novice or even an amateur to really honestly actually read and understand the source and behavior at the level I think you are expecting. Open source is a fine idea, but almost nobody really does this.