Question: Why doesn't L2 norm sorting work?


Why sorting these 4 vectors wrt L(+oo) norm returns a correct result bur sorting them wrt L2 norm doesn't (unless if I evaluate the norms as floats)?
 

restart:

kernelopts(version)

`Maple 2015.2, APPLE UNIVERSAL OSX, Dec 20 2015, Build ID 1097895`

(1)

V := [seq(LinearAlgebra:-RandomVector(2, generator=1..10), k=1..4)];

N2   := evalf(norm~(V, 2));
Ninf := norm~(V, +infinity);

V := [Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 8, (2) = 7}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 6, (2) = 2})]

 

[5.830951895, 10.63014581, 6.403124237, 6.324555320]

 

[5, 8, 5, 6]

(2)

Sorting wrt L(+oo) norm

sort(V, key=(t -> norm(t, +infinity)));  # correct

[Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 6, (2) = 2}), Vector(2, {(1) = 8, (2) = 7})]

(3)

Sorting wrt L(2) norm

sort(V, key=(t -> norm(t, 2))); # not correct
is(norm(V[4], 2) < norm(V[3], 2));

[Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 8, (2) = 7}), Vector(2, {(1) = 6, (2) = 2})]

 

true

(4)

sort(V, key=(t -> evalf(norm(t, 2)))); # correct

[Vector(2, {(1) = 3, (2) = 5}), Vector(2, {(1) = 6, (2) = 2}), Vector(2, {(1) = 4, (2) = 5}), Vector(2, {(1) = 8, (2) = 7})]

(5)

 


 

Download SortingVectors.mw


TIA

Please Wait...