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

Click For Summary
The discussion centers around the challenge of factoring expressions within matrices using Mathematica. A user seeks a method to simplify a matrix, specifically wanting to factor out common denominators. They find that standard functions like Simplify and Factor only operate on individual elements rather than the matrix as a whole. An alternative approach is suggested using Apply and Map to determine the least common multiple of the denominators, allowing for a simplified output. The conversation also touches on Mathematica's internal evaluation methods, which prioritize certain forms based on leaf counts, leading to unexpected results. The use of HoldForm is mentioned as a way to prevent automatic operations during display, but it is noted that navigating these functions can be complex. Additionally, open-source alternatives like Axiom, Sage, and Maxima are mentioned, though their complexity is acknowledged.
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.
 

Similar threads

  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
1K