3.2 Norm, Dot Product, and Distance in Rn

Three norm computations:

>> norm([3 4]) ans = 5 >> norm([3 5]) ans = 5.8310 >> norm([1 1 1]) ans = 1.7321

A normalization:

>> v=[1 1] v = 1 1 >> u=v/norm(v) u = 0.7071 0.7071

Computation of the distance between $(1,-2)$ and $(4,2)$:

>> norm([1 -2] - [4 2]) ans = 5

A dot product computation:

>> dot([1 2 -3], [2 -1 1]) ans = -3

Computation of the angle formed by two vectors:

>> u=[3 0]; >> v=[0 2]; >> acos( dot(u,v) / (norm(u)*norm(v)) ) ans = 1.5708

(Notice that the answer is a numerical approximation and the units are radians.)