On Mon, 11 May 2009, Sebastiano Putoto wrote:
I know my question may seem (it actually is) very banal, but I
can't figure out a way to check if two matrices are equal.
Example of checking exact equality:
<script>
set seed 567432
matrix m1 = mnormal(10,10)
matrix m2 = mnormal(10,10)
# Does m2 equal m1?
scalar meq = (m1 = m2)
set seed 567432
matrix m3 = mnormal(10,10)
# Does m3 equal m1?
scalar meq = (m1 = m3)
</script>
However, depending on the context, "near enough" might do:
<script>
matrix x = mnormal(10,2)
matrix xx = x'x
matrix xxi = inv(xx)
matrix xxii = inv(xxi)
# Does xxii equal xx (No)?
meq = (xx = xxii)
# Does xxii approximately equal xx?
tol = 1.0e-14
scalar approx_eq = abs(xx - xxii) < tol
</script>
(Obviously, "approximately equal" could be defined in various
ways.)
Allin Cottrell