Geometric Matrix Transformations

Note: This was originally designed to be a handout. It’s been edited some and now shared as a Mathematica notebook. Do look at each block of code to see what is going on. Mathematica does have built-in commands to do various types of transformations, but the point here is to see how multiplication by a matrix does the transformation. (Within the built-in functions, matrix multiplication is working behind the scenes.)

Another Note: Variables are not localized well.
Delete each cell containing the output of  Manipulate BEFORE evaluating the next one.

Single Matrix Transformations

Begin with Graphics

Graphics[{
{Blue,Arrow[{{0,0},{2,3}}]}
},Axes->True,PlotRange->10]

Include a Second Vector

Graphics[{
{Blue,Arrow[{{0,0},{2,3}}]},
{Red,Arrow[{{0,0},{2,3}}]}
},Axes->True,PlotRange->10]

This is the matrix we are going to start with

A={{-1,0},{0,1}}

MatrixForm lets you see it like a matrix, but you CANNOT do calculations with this, so we will keep matrices as lists with { }'s.

MatrixForm[A]

See what happens when you use matrix multiplication (DON'T FORGET THE DOT . ) with a vector.

A.{2,3}

Use the matrix to do the transformation. Notice the semicolon ; after the definition of A. Also, A is now multiplied by the original vector for the Red vector.

A={{-1,0},{0,1}};
Graphics[{
{Blue,Arrow[{{0,0},{2,3}}]},
{Red,Arrow[{{0,0},A.{2,3}}]}
},Axes->True,PlotRange->10]

Manipulate the Vector

Manipulate[
A={{-1,0},{0,1}};

Graphics[{
{Blue,Arrow[{{0,0},vector}]},
{Red,Arrow[{{0,0},A.vector}]}
},Axes->True,PlotRange->10],

{{vector,{2,3}},{-10,-10},{10,10},Locator}
]

Manipulate the Matrix

Manipulate[
A={{a11,a12},{a21,a22}};

Graphics[{
{Blue,Arrow[{{0,0},vector}]},
{Red,Arrow[{{0,0},A.vector}]}
},Axes->True,PlotRange->10,ImagePadding->5],
{{vector,{2,3}},{-10,-10},{10,10},Locator},
Row[{
Grid[{
{Control@{a11,Range[-2,2]},Spacer[5],Control@{a12,Range[-2,2]}},
{Control@{a21,Range[-2,2]},Spacer[5],Control@{a22,Range[-2,2]}}
}],
Spacer[40],Dynamic[MatrixForm[A]]
}],ControlType->PopupMenu,
Initialization:>{{{a11,a12},{a21,a22}}={{1,0},{0,1}}}
]

3D Version

Manipulate[
A={{a11,a12,a13},{a21,a22,a23},{a31,a32,a33}};

Graphics3D[{
{Blue,Arrow[{{0,0,0},vector}]},
{Red,Arrow[{{0,0,0},A.vector}]}
},Axes->True,PlotRange->10],
{{vector,{2,3,1}},{-10,-10,-10},{10,10,10},Slider},

Row[{
Grid[{
{Control@{a11,Range[-2,2]},Spacer[5],Control@{a12,Range[-2,2]},Spacer[5],Control@{a13,Range[-2,2]}},
{Control@{a21,Range[-2,2]},Spacer[5],Control@{a22,Range[-2,2]},Spacer[5],Control@{a23,Range[-2,2]}},
{Control@{a31,Range[-2,2]},Spacer[5],Control@{a32,Range[-2,2]},Spacer[5],Control@{a33,Range[-2,2]}}
}],
Spacer[40],Dynamic[MatrixForm[A]]
}],ControlType->PopupMenu,
Initialization:>{{{a11,a12,a13},{a21,a22,a23},{a31,a32,a33}}=IdentityMatrix[3]}
]

3D Version with Embellishments

Manipulate[
A={{a11,a12,a13},{a21,a22,a23},{a31,a32,a33}};

Show[
Graphics3D[{
{Blue,Line[{{0,0,0},vector}],Text["original",vector*1.1]},
{Red,Line[{{0,0,0},A.vector}],Text["result",A.vector*1.1]}
},Axes->True,PlotRange->10,AxesOrigin->{0,0,0},AxesLabel->Map[Style[#,12,Bold,Black]&,{"x","y","z"}],Boxed->False],

If[showplanes,
ParametricPlot3D[{{x,y,0},{x,0,y},{0,x,y}},{x,-10,10},{y,-10,10},Mesh->None,PlotStyle->Opacity[0.5]],
{}]
],

{showplanes,{True,False},Checkbox},
{{vector,{2,3,1}},{-10,-10,-10},{10,10,10},Slider},
Row[{
Grid[{
{Control@{a11,Range[-2,2]},Spacer[5],Control@{a12,Range[-2,2]},Spacer[5],Control@{a13,Range[-2,2]}},
{Control@{a21,Range[-2,2]},Spacer[5],Control@{a22,Range[-2,2]},Spacer[5],Control@{a23,Range[-2,2]}},
{Control@{a31,Range[-2,2]},Spacer[5],Control@{a32,Range[-2,2]},Spacer[5],Control@{a33,Range[-2,2]}}
}],
Spacer[40],Dynamic[MatrixForm[A]]
}],ControlType->PopupMenu,
Initialization:>{{{a11,a12,a13},{a21,a22,a23},{a31,a32,a33}}=IdentityMatrix[3]}
]

Multiple Transformations

Two matrices

Look at A and B below. Why does the result make sense? Try changing A and B into other transformation matrices.

Manipulate[
A={{-1,0},{0,1}};
B={{1,0},{0,0}};

Graphics[{
{Blue,Arrow[{{0,0},vector}],Text["original",vector*1.1]},
{Purple,Arrow[{{0,0},A.vector}]},
{Red,Arrow[{{0,0},B.A.vector}],Text["result",B.A.vector*1.1]}
},Axes->True,PlotRange->10,ImagePadding->5],

{{vector,{2,3}},{-10,-10},{10,10},Locator}
]

Make one of them a rotation matrix

Note that B is the identity matrix so you only see the rotation for now.

Manipulate[
t=Pi/4;
A={{Cos[t],-Sin[t]},{Sin[t],Cos[t]}};
B={{1,0},{0,1}};

Graphics[{
{Blue,Arrow[{{0,0},vector}],Text["original",vector*1.1]},
{Purple,Arrow[{{0,0},A.vector}]},
{Red,Arrow[{{0,0},B.A.vector}],Text["result",B.A.vector*1.1]}
},Axes->True,PlotRange->10,ImagePadding->5],

{{vector,{2,3}},{-10,-10},{10,10},Locator}
]

Manipulate the angle for the rotation matrix

Manipulate[
A={{Cos[t],-Sin[t]},{Sin[t],Cos[t]}};
B={{1,0},{0,1}};

Graphics[{
{Blue,Arrow[{{0,0},vector}],Text["original",vector*1.1]},
{Purple,Arrow[{{0,0},A.vector}]},
{Red,Arrow[{{0,0},B.A.vector}],Text["result",B.A.vector*1.1]}
},Axes->True,PlotRange->10,ImagePadding->5],

{{vector,{2,3}},{-10,-10},{10,10},Locator},
{{t,Pi/4},0,2Pi}
]

Change the B matrix to a projection

Manipulate[
A={{Cos[t],-Sin[t]},{Sin[t],Cos[t]}};
B={{1,0},{0,0}};

Graphics[{
{Blue,Arrow[{{0,0},vector}],Text["original",vector*1.1]},
{Purple,Arrow[{{0,0},A.vector}]},
{Red,Arrow[{{0,0},B.A.vector}],Text["result",B.A.vector*1.1]}
},Axes->True,PlotRange->10,ImagePadding->5],

{{vector,{2,3}},{-10,-10},{10,10},Locator},
{t,0,2Pi}
]

Show that order matters

Stretch out the vector and really look at each of the other vectors and consider the appropriate transformations. Matrices do not necessarily commute.

Manipulate[
A={{Cos[t],-Sin[t]},{Sin[t],Cos[t]}};
B={{1,0},{0,0}};

Graphics[{
{Blue,Arrow[{{0,0},vector}],Text["original",vector*1.1]},
{Purple,Arrow[{{0,0},A.vector}],Text["A",A.vector*1.1]},
{Red,Arrow[{{0,0},B.A.vector}],Text["BA",B.A.vector*1.1]},
{Darker[Orange,0.3],Arrow[{{0,0},B.vector}],Text["B",B.vector*1.1]},
{Darker[Green,0.4],Arrow[{{0,0},A.B.vector}],Text["AB",A.B.vector*1.1]}
},Axes->True,PlotRange->10],

{{vector,{2,3}},{-10,-10},{10,10},Locator},
{{t,Pi/4},0,2Pi}
]

Change the projection matrix into a reflection matrix

Manipulate[
A={{Cos[t],-Sin[t]},{Sin[t],Cos[t]}};
B={{1,0},{0,-1}};

Graphics[{
{Blue,Arrow[{{0,0},vector}],Text["original",vector*1.1]},
{Purple,Arrow[{{0,0},A.vector}],Text["A",A.vector*1.1]},
{Red,Arrow[{{0,0},B.A.vector}],Text["BA",B.A.vector*1.1]},
{Darker[Orange,0.3],Arrow[{{0,0},B.vector}],Text["B",B.vector*1.1]},
{Darker[Green,0.4],Arrow[{{0,0},A.B.vector}],Text["AB",A.B.vector*1.1]}
},Axes->True,PlotRange->10],

{{vector,{2,3}},{-10,-10},{10,10},Locator},
{{t,Pi/4},0,2Pi}
]

Abby Brown - Torrey Pines High School - Linear Algebra
Original March 2002? 2008? - Updated March 2018