Ensure Matrix is Symmetrical

MATLAB is a powerful piece of programming language used. However, since it runs on machine, there is always a finite level of precision, no matter how accurate the program is being developed.

For instance, a positive-definite matrix, A, is created with several repmat and permute commands, the symmetry of the entries within the matrix may no longer be exact. This will produce an error indicating that A is not a positive-definite matrix.

One of the way, which is also a very easy method, is to get rid of the slightest discrepancy between the symmetrical entry; for example, A(10,1) should be of the same value as A(1,10). To do so, simply compute the following command after obtaining A.

A = 0.5*(A + AT);

In this way, it ensures that the respective entries in the matrices are exactly symmetrical! A simply tip, but it’s worthwhile using it as a practice.