×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Please confirm or correct my evaluation of this code

## Please confirm or correct my evaluation of this code

(OP)

#### 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 [url=]here[/url] and [url=]here[/url].
Replies continue below

### RE: Please confirm or correct my evaluation of this code

(OP)
Nevermind, got help from somewhere else. Thanks anyway.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Close Box

# Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!