Updated pca.cpp with invariants