To transform the covariance matrix c to diagonal matrix:
Compute the eigenvectors and eigenvalues of matrix c
Construct the matrix P from eigenvectors as columns
Transpose the matrix P to get the inverse transformation matrix P^-1
Obtain the diagonal matrix D from eigenvalues
The orthogonal matrix M is given by M = P^-1* D^(1/2)* P
.
Here is the JavaScript code to obtain the orthogonal matrix M:
index.tsx680 chars20 lines
Note: This code assumes that you have access to a library for computing eigenvectors and eigenvalues of a matrix (eig()
function in this code). You can use any library of your choice that provides this functionality.
Also, this assumes that the numeric.js
library is installed and numeric.dot()
and numeric.inv()
are available for matrix multiplication and matrix inversion, respectivley.
gistlibby LogSnag