I wanted to write a quick function that calculates the logarithmic matrix norm with respect to the spectral norm. The formula is

$$ \mu_2(A) = \lambda_\mathrm{max}\left(\frac{A + A^T}2\right). $$

So I implemented it by

lognorm[A_] = First@Eigenvalues[(N[A] + Transpose[A])/2, 1];

Unfortunately, for lognorm[{{1, 2}, {3, 4}}] I get {{1, 5/2}, {5/2, 4}} as result. If I use

lognorm2[A_] = Eigenvalues[(N[A] + Transpose[A])/2, 1];

I get for lognorm2[{{1,2},{3,4}}] the result $\{\frac{1}{2} (5+\sqrt{34})\}$, which is strange because it is an exact result, although I added N in the definition of lognorm and lognorm2.

What is the reason for this and how can I write a lognorm function that works properly?


1 Answer 1


I found the answer: I have to use deferred definitions with :=. Otherwise Mathematica would calculate

First@Eigenvalues[(N[A] + Transpose[A])/2, 1]

which gives

1/2 (A+Transpose[A])

for some reason and then bind this to lognorm.

If I use := instead, the right hand side is evaluated each time the function is actually called.

See the documentation: http://reference.wolfram.com/language/tutorial/ImmediateAndDelayedDefinitions.html

Also note that Eigenvalues sorts the Eigenvalues by their absolute value, which means that Eigenvalues[{{1, 0}, {0, -5}},1] gives-5 instead of 1, because $|-5|>|1|$. A correct implementation would be

lognorm[A_] := Max[Eigenvalues[(N[A]+Transpose[A])/2]];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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