I have a A that I am analyzing using Principal Component Analysis (PCA) to reduce the dimensionality. Once I have reduced the dimensionality, I am attempting to fit a multivariate Gaussian distribution probability density function. Here is the code I used.

[U, ~, ~] = svd(1/m * (A)' * A);

P = @(z) 1/((2*pi)^(n/2)*det(Sigma)^0.5)*exp(-0.5*(z-Mu)'*pinv(Sigma)*(z-Mu));

delta = linspace(min(P(A_val)), max(P(A_val)), 1000);

Unfortunately, I have encountered three problems with my code that I am struggling to resolve. Firstly, I believe that P(A_val) should be a vector, but the code is not generating a vector. Secondly, the determinant of Sigma is becoming zero, resulting in an infinite delta value. Thirdly, I am using the formulation A_p = U(:,1:k)' * A for PCA, but I am encountering an error due to a size mismatch in the matrices. For this reason, change it to A_p = (U(:,1:k)' * A')'.