From: Nathan <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Angle between two vectors
Date: Tue, 23 Feb 2010 16:46:13 -0800 (PST)
Lines: 83
Message-ID: <>
References: <ef5ce9c.-1@webcrossing.raydaftYaTP> <> 
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: 1266972373 19596 (24 Feb 2010 00:46:13 GMT)
NNTP-Posting-Date: Wed, 24 Feb 2010 00:46:13 +0000 (UTC)
Injection-Info:; posting-host=; 
User-Agent: G2/1.0
X-HTTP-Via: 1.1 (squid/2.5.STABLE14)
X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) 
	Gecko/20100115 Firefox/3.6,gzip(gfe),gzip(gfe)
Xref: comp.soft-sys.matlab:611102

On Feb 23, 4:41 pm, "Benjamin McCrite" <>
>  Greg Heath <> wrote in message <>...
> > On Jul 9, 5:16 pm, "y Mehta" <mehtayogesh@gmail.(DOT).com> wrote:
> > > How do I find the angle between two unit vectors a and b? I know I
> > > can find cosine theta by the following formula:
> > > theta = acos(dot(a,b));
> > Invalid since it is possible that abs(dot(a,b)) > 1.
> > costheta = dot(a,b)/(norm(a)*norm(b));
> > theta = acos(costheta);
> > will give you the anser in the interval [0,pi].
> > > However, how do I know whether the angle is
> > > actually theta, or -theta or pi-theta or pi+theta??
> > Angles between vectors only lie in the interval [0,pi].
> > > Notice that the vectors are in three dimension (3d).
> > Dimensionality of the original space is irrelevant. As long as
> > norm(a)*norm(b) > 0, the vectors uniquely define a 2-d space when
> > dot(a,b) ~= 0 and a unique 1-d space otherwise.
> > Hope this helps.
> > Greg
> Can you tell me what norm(),cross() and dot() do?

Can you read the documentation?
The norm of a matrix is a scalar that gives some measure of the
magnitude of the elements of the matrix. The norm function calculates
several different types of matrix norms:

n = norm(A) returns the largest singular value of A, max(svd(A)).

n = norm(A,p) returns a different kind of norm, depending on the value
of p.

C = cross(A,B) returns the cross product of the vectors A and B. That
is, C = A x B. A and B must be 3-element vectors. If A and B are
multidimensional arrays, cross returns the cross product of A and B
along the first dimension of length 3.

C = cross(A,B,dim) where A and B are multidimensional arrays, returns
the cross product of A and B in dimension dim. A and B must have the
same size, and both size(A,dim) and size(B,dim) must be 3.

C = dot(A,B) returns the scalar product of the vectors A and B. A and
B must be vectors of the same length. When A and B are both column
vectors, dot(A,B) is the same as A'*B.

For multidimensional arrays A and B, dot returns the scalar product
along the first non-singleton dimension of A and B. A and B must have
the same size.

C = dot(A,B,dim) returns the scalar product of A and B in the
dimension dim.

Before asking what functions do, try to read and understand the
documentation for them. To view the documentation, you can type:

Where, in this case, FUNCTIONNAME is either cross, dot, or norm