Making an interactive visualization of the eigenvectors of two-dimensional matrices
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I've recently stumbled upon this very nice interactive visualization of eigenvectors of two-dimensional matrices, and how powers $A^k$ act on various vectors.
How can this sort of visualization be realized with Mathematica, leveraging its dynamical capabilities?
graphics dynamic visualization eigenvalues eventhandler
add a comment |Â
up vote
2
down vote
favorite
I've recently stumbled upon this very nice interactive visualization of eigenvectors of two-dimensional matrices, and how powers $A^k$ act on various vectors.
How can this sort of visualization be realized with Mathematica, leveraging its dynamical capabilities?
graphics dynamic visualization eigenvalues eventhandler
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I've recently stumbled upon this very nice interactive visualization of eigenvectors of two-dimensional matrices, and how powers $A^k$ act on various vectors.
How can this sort of visualization be realized with Mathematica, leveraging its dynamical capabilities?
graphics dynamic visualization eigenvalues eventhandler
I've recently stumbled upon this very nice interactive visualization of eigenvectors of two-dimensional matrices, and how powers $A^k$ act on various vectors.
How can this sort of visualization be realized with Mathematica, leveraging its dynamical capabilities?
graphics dynamic visualization eigenvalues eventhandler
graphics dynamic visualization eigenvalues eventhandler
edited 1 hour ago
asked 1 hour ago
glS
4,73911140
4,73911140
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
4
down vote
The following is an attempt to recreate a similar sort of interactive visualization, showing the eigenvectors (when real), and how the various points of the unit circle are transformed by the matrix.
The matrix can be chosen by moving its two column vectors using the mouse. I used EventHandler
for this, instead of Locator
s, for greater customizability and a more natural look.
Here is the full code:
arrowRepresentationActionMatrix[matrix_] :=
With[pts = MeshCoordinates@DiscretizeRegion@Region@Circle,
With[finalPts = Dot[matrix, #] & /@ pts,
Graphics[
PointSize@0.012, Point@finalPts,
Arrow /@ Thread@pts, finalPts
]
]];
DynamicModule[v1 = 0.7, -0.6, v2 = 0.6, 0.6, v3 = 1, 1,
movingPointIndex, matrix, frameSize = 1.5, numOfIterations = 30,
Row[
EventHandler[
Dynamic[
matrix = Transpose@v1, v2;
Show[
arrowRepresentationActionMatrix@matrix,
Graphics[
PointSize@0.02, Circle, Point@0, 0,
Red,
If[TrueQ[movingPointIndex == 1], PointSize@0.04,
PointSize@0.03],
Point@v1, Arrow@0, 0, v1,
Green,
If[TrueQ[movingPointIndex == 2], PointSize@0.04,
PointSize@0.03],
Point@v2, Arrow@0, 0, v2
,
Dynamic@Blue, PointSize@0.03, Point@v3, Arrowheads@0.02,
Arrow /@
Partition[NestList[Dot[matrix, #] &, v3, numOfIterations],
2, 1]
,
Dynamic@With[eigs = Eigenvectors@N@matrix,
If[MatchQ[eigs, __Real ..], Purple, Thickness@0.01,
InfiniteLine@-#, # & /@ eigs, ]
]
],
Frame -> True,
PlotRange -> Dynamic[-#, #, -#, # &@frameSize],
ImageSize -> 500
]
],
"MouseDown" :> With[mp = MousePosition["Graphics"],
movingPointIndex =
Position[v1, v2, v3, First@Nearest[v1, v2, v3, mp]][[1, 1]]
],
"MouseDragged" :> ReleaseHold[
Hold[Set][Hold[v1, v2, v3][[movingPointIndex]],
MousePosition["Graphics"]]
]
],
Column@
"PlotRange",
VerticalSlider[Dynamic@frameSize, 1, 10, 0.01,
Appearance -> "Labeled"]
, " ",
Column@
"Number of iterations",
VerticalSlider[Dynamic@numOfIterations, 1, 40, 1,
Appearance -> "Labeled"]
]
]
and this is the result:
This is really cool
â user6014
1 hour ago
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
4
down vote
The following is an attempt to recreate a similar sort of interactive visualization, showing the eigenvectors (when real), and how the various points of the unit circle are transformed by the matrix.
The matrix can be chosen by moving its two column vectors using the mouse. I used EventHandler
for this, instead of Locator
s, for greater customizability and a more natural look.
Here is the full code:
arrowRepresentationActionMatrix[matrix_] :=
With[pts = MeshCoordinates@DiscretizeRegion@Region@Circle,
With[finalPts = Dot[matrix, #] & /@ pts,
Graphics[
PointSize@0.012, Point@finalPts,
Arrow /@ Thread@pts, finalPts
]
]];
DynamicModule[v1 = 0.7, -0.6, v2 = 0.6, 0.6, v3 = 1, 1,
movingPointIndex, matrix, frameSize = 1.5, numOfIterations = 30,
Row[
EventHandler[
Dynamic[
matrix = Transpose@v1, v2;
Show[
arrowRepresentationActionMatrix@matrix,
Graphics[
PointSize@0.02, Circle, Point@0, 0,
Red,
If[TrueQ[movingPointIndex == 1], PointSize@0.04,
PointSize@0.03],
Point@v1, Arrow@0, 0, v1,
Green,
If[TrueQ[movingPointIndex == 2], PointSize@0.04,
PointSize@0.03],
Point@v2, Arrow@0, 0, v2
,
Dynamic@Blue, PointSize@0.03, Point@v3, Arrowheads@0.02,
Arrow /@
Partition[NestList[Dot[matrix, #] &, v3, numOfIterations],
2, 1]
,
Dynamic@With[eigs = Eigenvectors@N@matrix,
If[MatchQ[eigs, __Real ..], Purple, Thickness@0.01,
InfiniteLine@-#, # & /@ eigs, ]
]
],
Frame -> True,
PlotRange -> Dynamic[-#, #, -#, # &@frameSize],
ImageSize -> 500
]
],
"MouseDown" :> With[mp = MousePosition["Graphics"],
movingPointIndex =
Position[v1, v2, v3, First@Nearest[v1, v2, v3, mp]][[1, 1]]
],
"MouseDragged" :> ReleaseHold[
Hold[Set][Hold[v1, v2, v3][[movingPointIndex]],
MousePosition["Graphics"]]
]
],
Column@
"PlotRange",
VerticalSlider[Dynamic@frameSize, 1, 10, 0.01,
Appearance -> "Labeled"]
, " ",
Column@
"Number of iterations",
VerticalSlider[Dynamic@numOfIterations, 1, 40, 1,
Appearance -> "Labeled"]
]
]
and this is the result:
This is really cool
â user6014
1 hour ago
add a comment |Â
up vote
4
down vote
The following is an attempt to recreate a similar sort of interactive visualization, showing the eigenvectors (when real), and how the various points of the unit circle are transformed by the matrix.
The matrix can be chosen by moving its two column vectors using the mouse. I used EventHandler
for this, instead of Locator
s, for greater customizability and a more natural look.
Here is the full code:
arrowRepresentationActionMatrix[matrix_] :=
With[pts = MeshCoordinates@DiscretizeRegion@Region@Circle,
With[finalPts = Dot[matrix, #] & /@ pts,
Graphics[
PointSize@0.012, Point@finalPts,
Arrow /@ Thread@pts, finalPts
]
]];
DynamicModule[v1 = 0.7, -0.6, v2 = 0.6, 0.6, v3 = 1, 1,
movingPointIndex, matrix, frameSize = 1.5, numOfIterations = 30,
Row[
EventHandler[
Dynamic[
matrix = Transpose@v1, v2;
Show[
arrowRepresentationActionMatrix@matrix,
Graphics[
PointSize@0.02, Circle, Point@0, 0,
Red,
If[TrueQ[movingPointIndex == 1], PointSize@0.04,
PointSize@0.03],
Point@v1, Arrow@0, 0, v1,
Green,
If[TrueQ[movingPointIndex == 2], PointSize@0.04,
PointSize@0.03],
Point@v2, Arrow@0, 0, v2
,
Dynamic@Blue, PointSize@0.03, Point@v3, Arrowheads@0.02,
Arrow /@
Partition[NestList[Dot[matrix, #] &, v3, numOfIterations],
2, 1]
,
Dynamic@With[eigs = Eigenvectors@N@matrix,
If[MatchQ[eigs, __Real ..], Purple, Thickness@0.01,
InfiniteLine@-#, # & /@ eigs, ]
]
],
Frame -> True,
PlotRange -> Dynamic[-#, #, -#, # &@frameSize],
ImageSize -> 500
]
],
"MouseDown" :> With[mp = MousePosition["Graphics"],
movingPointIndex =
Position[v1, v2, v3, First@Nearest[v1, v2, v3, mp]][[1, 1]]
],
"MouseDragged" :> ReleaseHold[
Hold[Set][Hold[v1, v2, v3][[movingPointIndex]],
MousePosition["Graphics"]]
]
],
Column@
"PlotRange",
VerticalSlider[Dynamic@frameSize, 1, 10, 0.01,
Appearance -> "Labeled"]
, " ",
Column@
"Number of iterations",
VerticalSlider[Dynamic@numOfIterations, 1, 40, 1,
Appearance -> "Labeled"]
]
]
and this is the result:
This is really cool
â user6014
1 hour ago
add a comment |Â
up vote
4
down vote
up vote
4
down vote
The following is an attempt to recreate a similar sort of interactive visualization, showing the eigenvectors (when real), and how the various points of the unit circle are transformed by the matrix.
The matrix can be chosen by moving its two column vectors using the mouse. I used EventHandler
for this, instead of Locator
s, for greater customizability and a more natural look.
Here is the full code:
arrowRepresentationActionMatrix[matrix_] :=
With[pts = MeshCoordinates@DiscretizeRegion@Region@Circle,
With[finalPts = Dot[matrix, #] & /@ pts,
Graphics[
PointSize@0.012, Point@finalPts,
Arrow /@ Thread@pts, finalPts
]
]];
DynamicModule[v1 = 0.7, -0.6, v2 = 0.6, 0.6, v3 = 1, 1,
movingPointIndex, matrix, frameSize = 1.5, numOfIterations = 30,
Row[
EventHandler[
Dynamic[
matrix = Transpose@v1, v2;
Show[
arrowRepresentationActionMatrix@matrix,
Graphics[
PointSize@0.02, Circle, Point@0, 0,
Red,
If[TrueQ[movingPointIndex == 1], PointSize@0.04,
PointSize@0.03],
Point@v1, Arrow@0, 0, v1,
Green,
If[TrueQ[movingPointIndex == 2], PointSize@0.04,
PointSize@0.03],
Point@v2, Arrow@0, 0, v2
,
Dynamic@Blue, PointSize@0.03, Point@v3, Arrowheads@0.02,
Arrow /@
Partition[NestList[Dot[matrix, #] &, v3, numOfIterations],
2, 1]
,
Dynamic@With[eigs = Eigenvectors@N@matrix,
If[MatchQ[eigs, __Real ..], Purple, Thickness@0.01,
InfiniteLine@-#, # & /@ eigs, ]
]
],
Frame -> True,
PlotRange -> Dynamic[-#, #, -#, # &@frameSize],
ImageSize -> 500
]
],
"MouseDown" :> With[mp = MousePosition["Graphics"],
movingPointIndex =
Position[v1, v2, v3, First@Nearest[v1, v2, v3, mp]][[1, 1]]
],
"MouseDragged" :> ReleaseHold[
Hold[Set][Hold[v1, v2, v3][[movingPointIndex]],
MousePosition["Graphics"]]
]
],
Column@
"PlotRange",
VerticalSlider[Dynamic@frameSize, 1, 10, 0.01,
Appearance -> "Labeled"]
, " ",
Column@
"Number of iterations",
VerticalSlider[Dynamic@numOfIterations, 1, 40, 1,
Appearance -> "Labeled"]
]
]
and this is the result:
The following is an attempt to recreate a similar sort of interactive visualization, showing the eigenvectors (when real), and how the various points of the unit circle are transformed by the matrix.
The matrix can be chosen by moving its two column vectors using the mouse. I used EventHandler
for this, instead of Locator
s, for greater customizability and a more natural look.
Here is the full code:
arrowRepresentationActionMatrix[matrix_] :=
With[pts = MeshCoordinates@DiscretizeRegion@Region@Circle,
With[finalPts = Dot[matrix, #] & /@ pts,
Graphics[
PointSize@0.012, Point@finalPts,
Arrow /@ Thread@pts, finalPts
]
]];
DynamicModule[v1 = 0.7, -0.6, v2 = 0.6, 0.6, v3 = 1, 1,
movingPointIndex, matrix, frameSize = 1.5, numOfIterations = 30,
Row[
EventHandler[
Dynamic[
matrix = Transpose@v1, v2;
Show[
arrowRepresentationActionMatrix@matrix,
Graphics[
PointSize@0.02, Circle, Point@0, 0,
Red,
If[TrueQ[movingPointIndex == 1], PointSize@0.04,
PointSize@0.03],
Point@v1, Arrow@0, 0, v1,
Green,
If[TrueQ[movingPointIndex == 2], PointSize@0.04,
PointSize@0.03],
Point@v2, Arrow@0, 0, v2
,
Dynamic@Blue, PointSize@0.03, Point@v3, Arrowheads@0.02,
Arrow /@
Partition[NestList[Dot[matrix, #] &, v3, numOfIterations],
2, 1]
,
Dynamic@With[eigs = Eigenvectors@N@matrix,
If[MatchQ[eigs, __Real ..], Purple, Thickness@0.01,
InfiniteLine@-#, # & /@ eigs, ]
]
],
Frame -> True,
PlotRange -> Dynamic[-#, #, -#, # &@frameSize],
ImageSize -> 500
]
],
"MouseDown" :> With[mp = MousePosition["Graphics"],
movingPointIndex =
Position[v1, v2, v3, First@Nearest[v1, v2, v3, mp]][[1, 1]]
],
"MouseDragged" :> ReleaseHold[
Hold[Set][Hold[v1, v2, v3][[movingPointIndex]],
MousePosition["Graphics"]]
]
],
Column@
"PlotRange",
VerticalSlider[Dynamic@frameSize, 1, 10, 0.01,
Appearance -> "Labeled"]
, " ",
Column@
"Number of iterations",
VerticalSlider[Dynamic@numOfIterations, 1, 40, 1,
Appearance -> "Labeled"]
]
]
and this is the result:
edited 1 hour ago
answered 1 hour ago
glS
4,73911140
4,73911140
This is really cool
â user6014
1 hour ago
add a comment |Â
This is really cool
â user6014
1 hour ago
This is really cool
â user6014
1 hour ago
This is really cool
â user6014
1 hour ago
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185644%2fmaking-an-interactive-visualization-of-the-eigenvectors-of-two-dimensional-matri%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password