I have this matlab code that I want to write in Eigen
:
[V_K,D_K] = eig(K);
d_k = diag(D_K);
ind_k = find(d_k > 1e-8);
d_k(ind_k) = d_k(ind_k).^(-1/2);
K_half = V_K*diag(d_k)*V_K';
So far the code that I've written is (the last part is based following this example):
Eigen::EigenSolver<Eigen::MatrixXf> es (K,true);
Eigen::MatrixXcf v = es.eigenvalues();
v = (v.array()).select(1/std::sqrt(v),v);
This is obviously wrong (first of all, you cannot apply std::sqrt(v)
on Eigen::MatrixXcf
), but I didn't figure out how to write it. Can you help me?