2
$\begingroup$

The nuclear norm is defined by this [from wikipedia]:

$$\|A\|_* = \text{trace} \left( \sqrt{A^*A} \right) = \sum_{i=i}^{\min\{m,n\}}\sigma_i(A)$$

I get the derivation of this equation. However, I wanted to test it in MATLAB. So used this script:

clc;
clear;
close all;

P = rand([3,4]);
PTP = P'*P;

%compute trace(P'*P)
B = sqrt(P'*P);
S1 = trace(B)

%Compute sum of sigma_i(P)
E = svd(P);
S2 = sum(E)

%Do the same for eigenvalues
E3 = sqrt(eig(P*P'));
S3 = sum(E3)

But for some reason, the values inside S1 and S2 does not match. I do not understand where I did wrong. Could anybody help?

$\endgroup$
  • $\begingroup$ Welcome to the site by the way. It can be good to learn mathjax typesetting for this site. I helped you turn the wikipedia equation into mathjax code. I think there is a tutorial somewhere. math.meta.stackexchange.com/questions/5020/… $\endgroup$ – mathreadler Apr 9 '19 at 7:34
4
$\begingroup$

On the line

B = sqrt(P'*P);

"sqrt" in Matlab calculates element-wise square root.

You probably want to use "sqrtm" : matrix square root instead.

$\endgroup$
  • $\begingroup$ That solves the problem! I forgot that it does element wise square root! :( $\endgroup$ – ponir Apr 9 '19 at 0:22
  • 1
    $\begingroup$ @ponir It is good because it meant you did not misunderstand something. It is same with other matrix functions in Matlab, they end with letter "m", for example expm for matrix exponential function. If you are happy with answer please press accept answer button. :) $\endgroup$ – mathreadler Apr 9 '19 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.