# Angle between two vectors?

I have been taught that the angle between two vectors is supposed to be their inner product. However, the book I'm reading states:

Recall that the angle between two vectors $u = (u_0,\ldots,u_{n−1})$ and $v = (v_0,\ldots, v_{n−1})$ in $\mathbb{C}^n$ (the complex plane) is just a scaling factor times their inner product.

What is a "scaling factor"?

-
This is wrong. The angle between two vectors $u$ and $v$ is $\cos^{-1} \left( \frac{u \cdot v}{||u|| ||v||} \right)$. – Qiaochu Yuan May 25 '12 at 23:22
@Qiaochu Yuan: That would be for real vectors – Henry May 25 '12 at 23:37
@Farhad What book is this from? It seems poorly worded, at best. – process91 May 25 '12 at 23:42
@MichaelBoratko It's from "Algorithms" by S.Dasgupta, page 73. Mathematically, it's not the greatest book but it does provide creative computer science algorithms. – user26649 May 26 '12 at 16:44
The statement reflects that the notion of an angle between two vectors in an inner product space depends on the inner product. The dot product described in some answers below is not the only admissible inner product, and so simply defining the angle by the dot product is a special case, not a general definition of the angle. – Andrew Sep 27 '15 at 8:45

the angle between two vectors is supposed to be their inner product

is incorrect, as is the statement from the book. On the Wikipedia page on the dot product, you can see the correct formula for the angle between two complex vectors $u$ and $v$ (thanks to Henry for catching the earlier mistake): $$\theta=\arccos\left(\frac{\operatorname{Re}(u\cdot v)}{\|u\|\|v\|}\right)$$ where the inner product $u\cdot v$ is defined to be $$u\cdot v=\sum_{k=0}^{n-1} u_k\overline{v_k}$$ I would guess that perhaps the intended meaning of the "scaling factor" is as follows: when $u$ and $v$ are unit vectors, we have $$\cos(\theta)=\operatorname{Re}(u\cdot v)$$ while when $u$ and $v$ are arbitrary non-zero vectors, we have $$\cos(\theta)=\frac{\operatorname{Re}(u\cdot v)}{\|u\|\|v\|}$$ (the quantities $\|u\|$ and $\|v\|$ are both equal to $1$ when $u$ and $v$ are unit vectors). This would make $$\frac{1}{\|u\|\|v\|}$$ the "scaling factor", though it is scaling the formula for the cosine of the angle, not the angle itself.

-
Thanks! Assuming that the author made a mistake, what is a "scaling factor"? – user26649 May 25 '12 at 23:25
I've added what I assume was intended. – Zev Chonoles May 25 '12 at 23:30
If you go further down the wikipedia page to "Complex vectors", it says the angle between two complex vectors is then given by $$\cos\theta = \frac{\operatorname{Re}(\mathbf{a}\cdot\mathbf{b})}{\|\mathbf{a}\|\,\|\mathbf{b}‌​\|}.$$ Otherwise you will be taking the arccosine of a complex number. – Henry May 25 '12 at 23:34
@Henry: Thank you for pointing that out, I've corrected my answer. – Zev Chonoles May 25 '12 at 23:40
@Pedro77: No, it's not wrong. For two vectors $\mathbf{a},\mathbf{b}\in\mathbb{R}^3$, it's true that $$\tan^{-1}\left(\frac{\|\mathbf{a} \times \mathbf{b}\|}{\mathbf{a} \cdot\mathbf{b}}\right) =\tan^{-1}\left( \frac{\|\mathbf{a}\|\|\mathbf{b}\| \sin(\theta)}{\|\mathbf{a}\| \|\mathbf{b} \|\cos(\theta)}\right)= \tan^{-1} \left(\frac{\sin(\theta)}{\cos(\theta)}\right)= \tan^{-1}(\tan(\theta))=\theta$$ As was explained in the answer you linked to, that approach is chosen for numerical stability, which is a computational concern. Two formulas can both be correct but have different stability. – Zev Chonoles Apr 29 at 19:15

Let $\vec{a},\vec{b}\in \mathbb{C}^n$ be nonzero, where $\vec{a} = (a_1,...,a_n)$ and $\vec{b} = (b_1,...,b_n)$. As a vector space over $\mathbb{R}$, the space $\mathbb{C}^n$ is isomorphic to $\mathbb{R}^{2n}$. That is, for $\vec{a}$ and $\vec{b}$ there corresponds vectors $\vec{x},\vec{y}\in\mathbb{R}^{2n}$ (respectively) such that $$\vec{x} = \begin{pmatrix} \text{Re}\,(a_1) \\ \text{Im}\,(a_1) \\ \text{Re}\,(a_2) \\ \text{Im}\,(a_2) \\ \vdots \ \\ \text{Re}\,(a_n) \\ \text{Im}\,(a_n) \end{pmatrix} \qquad \text{and} \qquad \vec{y} = \begin{pmatrix} \text{Re}\,(b_1) \\ \text{Im}\,(b_1) \\ \text{Re}\,(b_2) \\ \text{Im}\,(b_2) \\ \vdots \ \\ \text{Re}\,(b_n) \\ \text{Im}\,(b_n) \end{pmatrix} \ .$$

Recall that $||\,\vec{x}+\vec{y}\,||^2 = ||\, \vec{x}\, ||^2 + ||\,\vec{y}\,||^2+2\,\vec{x}\cdot\vec{y}$ and $$\cos\theta = \frac{\vec{x}\cdot\vec{y}}{||\,\vec{x}\,||\,||\,\vec{y}\,||} \ ,$$ where $\theta$ is the angle between $\vec{x}$ and $\vec{y}$ (and also the angle between $\vec{a}$ and $\vec{b}$).

$\quad$ We will now show that $\vec{x}\cdot\vec{y} = \text{Re}\,(\vec{a}\cdot\vec{b})$. It is easy to show that $$||\,\vec{a}+\vec{b}\,||^2 = ||\,\vec{a}\,||^2+||\,\vec{b}\,||^2 + \vec{a}\cdot\vec{b} + \overline{\vec{a}\cdot\vec{b}}$$ and $$||\,\vec{x}+\vec{y}\,||^2 = ||\,\vec{x}\,||^2+||\,\vec{y}\,||^2+2\,\vec{x}\cdot\vec{y}.$$ It is also easily show that $||\,\vec{x}\,|| = ||\,\vec{a}\,||$ and $||\,\vec{y}\,||=||\,\vec{b}\,||$. Consequently, $||\,\vec{x}+\vec{y}\,|| = ||\,\vec{a}+\vec{b}\,||$. Therefore, $||\,\vec{a}+\vec{b}\,||^2 = ||\,\vec{a}\,||^2+||\,\vec{b}\,||^2+2\,\vec{x}\cdot\vec{y}.$ We thus obtain $$\vec{x}\cdot\vec{y} = \frac{1}{2}\left( \vec{a}\cdot\vec{b} + \overline{\vec{a}\cdot\vec{b}} \right).$$

$\quad$ But observe that $\vec{a}\cdot\vec{b} = \alpha + i\beta$ for some $\alpha,\beta\in\mathbb{R}$. Then $$\vec{a}\cdot\vec{b} + \overline{\vec{a}\cdot\vec{b}} = (\alpha + i\beta)+(\alpha-i\beta) = 2\alpha = 2\text{Re}\,(\vec{a}\cdot\vec{b}).$$ Hence, $$\vec{x}\cdot\vec{y} = \frac{1}{2}\left( \vec{a}\cdot\vec{b} + \overline{\vec{a}\cdot\vec{b}} \right) = \text{Re}\,(\vec{a}\cdot\vec{b}).$$

And thus we finally have $$\cos\theta = \frac{\text{Re}\,(\vec{a}\cdot\vec{b})}{||\,\vec{a}\,||\,||\,\vec{b}\,||} \ .$$ Therefore, $$\theta = \arccos \frac{\text{Re}\,(\vec{a}\cdot\vec{b})}{||\,\vec{a}\,||\,||\,\vec{b}\,||}.$$

-
How you come up with it, you wrote it is very easy to proof, $||a⃗ +b⃗ ||^2=||a⃗ ||^2+||b⃗ ||^2+a⃗ ⋅b⃗ +\overline{a⃗ ⋅b⃗ }$. I could not follow you with this can you please give some more detail on it. thank – Kiran Mar 5 '14 at 9:37

The dot product, inner product or scalar product is defined as: $$\vec u \cdot \vec v = u_1\cdot v_1 + \ldots + u_n\cdot v_n = \|\vec u\|\cdot\|\vec v\|\cdot\cos(\angle\vec u\vec v)$$ In other words, if the two vectors are unit vectors, their dot product is the cosine of the angle between them. To get to that point, simply normalize the two vectors: $$\frac{\vec u}{\|\vec u\|}\cdot\frac{\vec v}{\|\vec v\|}=\frac{\vec u \cdot \vec v}{\|\vec u\|\cdot\|\vec v\|}=\cos(\angle\vec u\vec v)$$ Take the arcus cosine of the quotient and you get the actual angle.

-
This formula is only correct when $\vec{u}$ and $\vec{v}$ are vectors in $\mathbb{R}^n$, i.e. the numbers $u_i$ and $v_i$ are real numbers. The correct formula for complex vectors (which are what are asked about in the question) is given in my answer. – Zev Chonoles May 27 '12 at 1:27
Oops, missed that. – Wormbo May 27 '12 at 8:07