Message Boards Message Boards

GROUPS:

Factoring out the factor of a matrix with the results elements Abs <=1

Posted 11 days ago
215 Views
|
3 Replies
|
3 Total Likes
|

I have some matrices, which are all composed of numbers with absolute value less than or equal to 1.
I want to find the common factor for each of them, so that the final elements in a matrix still have the absolute values ≤ 1 and is as close to 1 as possible. The following is an example:

In[903]:= FactorMatrix//ClearAll;
FactorMatrix[m_?MatrixQ]:=Block[{gcd},
gcd = PolynomialGCD @@ Flatten[m];
{gcd, m/gcd}
]

ubasSGBC141
%//FactorMatrix
ubasSG229me
%//FactorMatrix

Out[905]= {{1/2, 0, 0}, {0, 1/2, 0}, {0, 0, 1/2}}

Out[906]= {1/2, {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}}

Out[907]= {{-(1/16), -(1/16), 1/8}, {1/16, 0, 1/16}, {0, 1/16, 1/16}}

Out[908]= {1/16, {{-1, -1, 2}, {1, 0, 1}, {0, 1, 1}}}

In the above results, the first one meets the requirements, but the second one fails. Specifically, the result should be as follows:

{1/8, {{-(1/2), -(1/2), 1}, {1/2, 0, 1/2}, {0, 1/2, 1/2}}}

Are there any hints for achieving this goal?

Regards,
Zhao

POSTED BY: Hongyi Zhao
3 Replies
Posted 11 days ago

Maybe like this?

In[27]:= m1 = {{1/2, 0, 0}, {0, 1/2, 0}, {0, 0, 1/2}};
In[28]:= m2 = {{-(1/16), -(1/16), 1/8}, {1/16, 0, 1/16}, {0, 1/16, 1/16}};

In[29]:= f[m_?MatrixQ] := m/Max[Abs@m]

In[30]:= f[m1]
Out[30]= {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}

In[31]:= f[m2]
Out[31]= {{-(1/2), -(1/2), 1}, {1/2, 0, 1/2}, {0, 1/2, 1/2}}
POSTED BY: Hans Milton
Posted 11 days ago

What about the following version?

In[44]:= m1 = {{1/2, 0, 0}, {0, 1/2, 0}, {0, 0, 1/2}};
m2 = {{-(1/16), -(1/16), 1/8}, {1/16, 0, 1/16}, {0, 1/16, 1/16}};
m3 = {{-(1/16), -(1/16), -1/8}, {-1/16, 0, -1/16}, {0, -1/16, -1/16}};
f[m_?MatrixQ] := m/Max[Abs[m]]
f[m1]
f[m2]
f[m3]

Out[48]= {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}

Out[49]= {{-(1/2), -(1/2), 1}, {1/2, 0, 1/2}, {0, 1/2, 1/2}}

Out[50]= {{-(1/2), -(1/2), -1}, {-(1/2), 
  0, -(1/2)}, {0, -(1/2), -(1/2)}}
POSTED BY: Hongyi Zhao
Posted 11 days ago

Yes, Zhao, I was editing in the negative max correction just before I saw your post.

POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract