masijade
Computer
- Mar 20, 2011
- 3
Code:
[ignore,maxind] = max(abs(U),[],1);
negloc = (U(maxind + (0:N_f:(N_f-1)*N_f)) < 0);
U(:,negloc) = -U(:,negloc);
(N_f is the number of columns in the matrix (actually the number of rows, but it is a square matrix, so same-same))
I am assuming that these two line multiply all the elements of the columns where the maximum absolute value comes from a negative number by -1, without modifying or eliminating any other columns. Is this correct?
Code:
[U,D] = eig((correlation_matrix+correlation_matrix')/2);
D = diag(D);
norma=diag(1./sqrt(U.^2*D));
Okay, my evaluation of the last line above
Square the elements of Matrix U, multiply that D, and then "squareroot" all the elements, then apply the diag method.
My question is, is D a vector or a "square" matrix at that point. I am assuming a Vector as norma is used as a square matrix later in the program, and D should be, after "eig" a "square" matrix, and so a vector after the call to diag. I find it very bad form to use "D" as the variable for both a vector and a matrix, if that's the case though.
I cannot run this code, as I do not have a matlab environment. I am porting this code to something else, and I just want to make sure that my "assumptions" are correct, or get them corrected, if they are not.
I am also posting this question here and here.