Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- positivizeMatrix[X_] := Module[{res},
- res = X;
- auxsystDP = Eigensystem[X];
- duDP = DiagonalMatrix[auxsystDP[[1]]];
- powerDP = 20;
- While[Not[PositiveDefiniteMatrixQ[res]],
- wDP =
- ReplacePart[
- duDP, {i_, i_} /;
- duDP[[i, i]] <= 0 :> $MachineEpsilon*2^(-powerDP)];
- (*Adding the smallest nugget possible.*)
- res =
- Transpose[auxsystDP[[2]]].wDP.Inverse[Transpose[auxsystDP[[2]]]];
- (*this matrix is still not symmetric, only PD*)
- powerDP--;
- ];
- Print[PositiveDefiniteMatrixQ[res]];
- res = 0.5*(res + Transpose[res]);
- Print[PositiveDefiniteMatrixQ[res]];
- ];
Add Comment
Please, Sign In to add comment