The problem of computing a nearest positive semidefinite matrix (notation used to an arbitrary real matrix A is considered. The criterion of approximation is the distance where the norm is chosen to be either Frobenius or 2-norm. The paper consists of two parts. In the first part the author proves that the nearest unique positive approximant of A in the Frobenius norm is where and H is the symmetric polar factor of B, and the corresponding distance from A is where
In the second part the problem is studied in 2-norm. Examining from a computational view point the famous Halmos formula for the distance the author proposes two algorithms to estimate as well as the positive approximant (which is not unique in general): (i) an efficient bisection algorithm of low accuracy that is where f is a relative error tolerance and tol is an absolute error tolerance; (ii) a hybrid Newton-bisection type algorithm for high accuracy computations. The problem of computational testing for positive definiteness as well as some details concerning the implementation of algorithm (ii) are discussed. Numerical examples are presented.