MATLAB: Creat a positive definite matrix, which way is better

MATLABnumerical analysisnumerical stabilitypositive definite matrix; numerical error;

Hi everyone,
Suppose I have a positive definite matrix P and a non-singular matrix A, I realised there is a small numerical difference between K=(I-A)*P*(I-A)' and K_=P-A*P-P*A'+A*P*A'. If I want to create a positive definite matrix, which way should I use?
In some extreme cases, is it possible that K or K_ has very small negative eigenvalues?
Thanks

Best Answer

Yes, if A has eigenvalues close to 1, then I believe neither K nor K_ will be positive definite with numerical robustness.