I think that in order to find the smallest n
such that n*pinv(A)
is a matrix of integers, one would have to find the least common multiple of the denominators of pinv(A)
. Luckily, the base function lcm
can find the least common multiple of a series of numbers.
So something like:
function npinv(A)
rA = Rational.(A)
B = (transpose(rA)*rA)\transpose(rA)
n = lcm([denominator(e) for e in B])
return n, B
end
Would work I think
EDIT: typos in code