Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have vector u=(x,y) and i need to create matrix M: M*u=(1,0).

But that matrix has to rotate vector, instead of keep and scale the x unit. So when i apply it on different vectors, the angle between them won't change.

Btw, this isn't homework! We haven't learned any matrices at school yet. ;)

share|cite|improve this question
But, when you talk of rotating, is (x,y) on the unit circle? If so, if you can find out the angle of the vector 0u , i.e., the number 'r' of radians at (x,y) , starting at (1,0), all you need to do is to rotate (x,y) by '-r', and this is just given by a matrix with $a_ii=cost$; $a_1i=sint$ and $a_{21}=-sint$. Maybe the simplest example is that of using a matrix with all entries $\frac {2^{0.5}}{2}$ , except for $a_{21}= -\frac {2^{0.5}}{2}$ – gary Sep 11 '11 at 8:57
It might be quite helpful if you show us a picture of what you want to happen... – J. M. Sep 11 '11 at 9:28
up vote 7 down vote accepted

Your problem is equivalent to find the transformation between the $x,y$ coordinates of a point and the $x^{\prime },y^{\prime }$ coordinates of the same point in a rotated system of coordinates, followed by a multiplication by the factor $k=1/\sqrt{x^{2}+y^{2}}$, so that $x^{\prime \prime }=kx^{\prime }=1$ and $y^{\prime \prime }=kx^{\prime }=0$. The rotation angle should be $\theta =\arctan \frac{y}{x}$.

enter image description here

From trigonometry, we know that

$$ \begin{eqnarray*} &&\left\{ \begin{array}{c} x^{\prime }=x\cos \theta +y\sin \theta =\sqrt{x^{2}+y^{2}} \\ y^{\prime }=-x\sin \theta +y\cos \theta =0 \end{array} \right. \end{eqnarray*} $$ and since

$$ \begin{eqnarray*} \cos \left( \arctan \frac{y}{x}\right) &=&\frac{x}{\sqrt{x^{2}+y^{2}}} \\ \sin \left( \arctan \frac{y}{x}\right) &=&\frac{y}{\sqrt{x^{2}+y^{2}}}, \\ \end{eqnarray*} $$

we have $$\begin{eqnarray*} \left\{ \begin{array}{c} x^{\prime \prime }=\frac{1}{\sqrt{x^{2}+y^{2}}}x^{\prime }=\frac{x^{2}}{ x^{2}+y^{2}}+\frac{y^{2}}{x^{2}+y^{2}}=1 \\ y^{\prime \prime }=\frac{1}{\sqrt{x^{2}+y^{2}}}y^{\prime }=-\frac{xy}{ x^{2}+y^{2}}+\frac{xy}{x^{2}+y^{2}}=0. \end{array} \right. \end{eqnarray*} $$

We haven't learned any matrices at school yet.

In matrix notation$^1$

$$ \begin{eqnarray*} \begin{pmatrix} x^{\prime \prime } \\ y^{\prime \prime } \end{pmatrix} &=&\frac{1}{\sqrt{x^{2}+y^{2}}} \begin{pmatrix} x^{\prime } \\ y^{\prime } \end{pmatrix} = \begin{pmatrix} \frac{x}{x^{2}+y^{2}} & \frac{y}{x^{2}+y^{2}} \\ -\frac{y}{x^{2}+y^{2}} & \frac{x}{x^{2}+y^{2}} \end{pmatrix} \begin{pmatrix} x \\ y \end{pmatrix} = \begin{pmatrix} 1 \\ 0 \end{pmatrix}. \end{eqnarray*} $$

So $$ M= \begin{pmatrix} \frac{x}{x^{2}+y^{2}} & \frac{y}{x^{2}+y^{2}} \\ -\frac{y}{x^{2}+y^{2}} & \frac{x}{x^{2}+y^{2}} \end{pmatrix}. $$


$^1$ Product of a $2\times 2$ matrix by a $2\times 1$ matrix $$ \begin{pmatrix} a_{11} & a_{12} \\ a_{21} & a_{22} \end{pmatrix} \begin{pmatrix} b_{1} \\ b_{2} \end{pmatrix} = \begin{pmatrix} a_{11}b_{1}+a_{12}b_{2} \\ a_{21}b_{1}+a_{22}b_{2} \end{pmatrix} $$

and product between a scalar $\alpha$ and a $2\times 1$ matrix

$$\alpha \begin{pmatrix} c_{1} \\ c_{2} \end{pmatrix} = \begin{pmatrix} \alpha c_{1} \\ \alpha c_{2} \end{pmatrix} $$

share|cite|improve this answer

I assume you want a 2$\times$2 rotation matrix that sends $\vec{u}=(x,y)$ to $\vec{e}_1=(1,0)$. (The question is a bit unclear in my opinion: what does it mean to "keep and scale the x unit"? Isn't that an oxy-moron? I assume you want to preserve angles under transformation, i.e. $\angle\vec{a}\vec{b}=\angle(M\vec{a})(M\vec{b})$, right?) The dot product's angle formula gives $\cos\theta=\vec{u}\cdot\vec{e_1}/r$, where $\theta$ is the angle from $\vec{e}_1$ to $\vec{u}$ and $r=\|\vec{u}\|=\sqrt{x^2+y^2}$ is the magnitude. Now we use this to find the entries of the rotation matrix $R(-\theta)$ (the matrix transforms counterclockwise normally, so to get it to go backwards we need to negate the angle sign); see the Wikipedia link. Note $\sin^2+\cos^2=1$. Moreover, we have to divide this rotation matrix by another $r$ so that it scales down $\vec{u}$ to unit size. Thus we have


You can check that this indeed sends $\vec{u}$ to $\vec{e}_1$.

share|cite|improve this answer
$(x/r)x+(y/r)y=(x^2+y^2)/r=r^2/r=r$ instead of $1$. In your notation I have computed $$M=\begin{pmatrix} \frac{x}{r^2} & \frac{y}{r^{2}} \\ -\frac{y}{r^{2}} & \frac{x}{r^{2}} \end{pmatrix}.$$ – Américo Tavares Sep 11 '11 at 13:04
@Americo: Thanks for the catch. Fixed. – anon Sep 11 '11 at 18:55

M =

[ x y
  -y x ]
/ (x^2 + y^2) ^(1/2)
share|cite|improve this answer
The question was how to create it... – anon Sep 11 '11 at 9:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.