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