Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Precision in Matrix Multiplication

    Hello Statalist,

    I am trying to multiply symmetric square matrices, A and B, in the following form:
    C = A*B*A

    where C should be a symmetric matrix of the same size as A and B. However, when I multiply using Mata, I end up with a non-symmetric matrix for C. I suspect that this has to do with the precision in multiplication as the elements in matrices A*B and C are both very close to zero (to the order of 10^-14 and smaller).

    So far, I have tried using quadcross(A,B) to improve precision to no avail. Unfortunately, I cannot rule out a singular B, so it is not possible to decompose B into say B=LU and calculate C=(AL)*(UA). Is there any way in Mata to improve the precision in obtaining C?

    Thanks,
    Chang


  • #2
    Code:
    help mf_edittozero
    help mf_makesymmetric
    help mf__equilrc
    are some functions that you might want to look into.

    It's a bit surprising that quadcross() wasn't adequate . . .

    Comment


    • #3
      Please try the following and report back the results:

      Code:
      mata:
      issymmetriconly(A) 
      issymmetriconly(B) 
      end

      Comment


      • #4
        Originally posted by Hua Peng (StataCorp) View Post
        Please try the following and report back the results:

        Code:
        mata:
        issymmetriconly(A)
        issymmetriconly(B)
        end
        I get 1 for both matrices A and B. To make it more clear, matrix B is equal to X'YX where Y is a k-by-k matrix of ones.

        Interesting thing about this is that I found out that when I make off-diagonal elements of Y slightly different than one (say 0.9999), then I get a symmetric matrix C but B doesn't pass the
        Code:
         issymmetriconly(B)
        test.
        Last edited by Chang Lee; 30 Oct 2017, 14:42.

        Comment

        Working...
        X