4
$\begingroup$

Here is a simple eigenvector problem solution

m = {{2, Sqrt[15]}, {Sqrt[15], 4}};
v = Eigenvectors[m]

However, the list of vectors v is not normalized. The command

Normalize[v]

returns an error. It seems Normalize doesn't want a list of vectors. The following works just fine:

u = Table[Normalize[v[[i]]], {i, 2}];

...but it seems clunky to me. I found an alternate way to use Normalize with a second argument, namely

Normalize[v, Norm]

but the list of vectors returned is not the same as u.

Is there something better than using Table to normalize the list of eigenvectors?

$\endgroup$
  • $\begingroup$ try Normalize /@ v? $\endgroup$ – kglr Mar 4 '17 at 14:30
7
$\begingroup$

Here's a range of incremental improvements:

Table[Normalize[v[[i]]], {i, 2}]

Table[Normalize[v[[i]]], {i, Length[v]}] (* like a for loop in other languages *)

Table[Normalize[ev], {ev, v}] (* like a for each loop in other languages *)

Map[Normalize, v]

Normalize /@ v (* shorthand for Map *)

Look up Map and all the syntaxes of Table and read this:

Note that Eigenvectors will return normalized eigenvectors if its input are floating point numbers, but not if the input is exact. Eigenvactors@N[m] gives a normalized approximate result because N[m] is floating point. Eigenvalues[m] doesn't because m is exact.


Normalize[v, Norm] does not do what you think it is doing. Normalize[vector, function] simply computes vector / function[vector]. In your case it uses Norm[v], which is a matrix norm, not a vector norm.

$\endgroup$
5
$\begingroup$

Normalize is not a Listable function, which means that you cannot expect it to act on a list of arguments in the same way that it acts on an argument. That is why you have to Map its action into the list of vectors.

So as @kglr writes in the comments, Map[Normalize,v], or equivalently Normalize/@v, will do the job:

Normalize /@ {{1, 1}, {1, -1}}

(* {{1/Sqrt[2], 1/Sqrt[2]}, {1/Sqrt[2], -(1/Sqrt[2])}} *)
$\endgroup$
  • $\begingroup$ Thank you both very much. This is just what I needed. $\endgroup$ – Jim Napolitano Mar 4 '17 at 16:39
  • $\begingroup$ Another way to think about your problem (and the answers) is that you were trying to normalize a matrix. Instead you want to normalize each row (vector) in the matrix. Thus you have to map Normalize to each of the rows. $\endgroup$ – David G. Stork Mar 4 '17 at 19:17

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.