rayleigh quotient Algorithm

If we repair the complex matrix M, then the resulting Rayleigh quotient map (considered as a function of X) completely determines M via the polarization identity; indeed, this remains true even if we let M to be non-Hermitian. In quantum mechanics, the Rayleigh quotient gives the expectation value of the observable corresponding to the operator M for a system whose state is given by x.

rayleigh quotient source code, pseudocode and analysis