Exercise 6.
Matrices and Linear Algebra.

Ex 1. Define a function matr[n_] that generates the matrix (({{1, 1, ..., 1}, {2, 2, ..., 2}, {..., ..., ..., ...}, {n, n, n, n}})) and multiplies the i-th row with (({{i}, {4}})), i=1,...,n.

matr[n_]:=(
A=Table[Table[j,{i,n}],{j,n}];
For[i=1,i≤n,i++,
A[[i]]*=Binomial[i,4]^2];
A
)
matr[10]//MatrixForm

Ex 2: Let A=(({{1, 0.0175`, -0.015`}, {0.04`, 1.06`, -0.06`}, {-0.06`, 0.315`, 0.8`}})) . Compute (A^1000000) by multiplying A 1000000 times and by first diagonalizing the matrix. Compare the computational times, using the TimeUsed[] function.

start=TimeUsed[];
A={{1,2,3},{2,3,4},{3,4,5}}//N;
res=A;
For[i=2,i≤100000,i++,
res=res.A]
end=TimeUsed[];
Print["Time:",end-start,"s"]
res

start=TimeUsed[];
A={{1,2,3},{2,3,4},{3,4,5}};
Λ=DiagonalMatrix[Eigenvalues[A]]//N;
T=Transpose[Eigenvectors[A]]//N;
res=T.((Λ^100000)).Inverse[T];
end=TimeUsed[];
Print["Time:",end-start,"s"]
res

Thus, we compute matrix powers by first diagonalizing (or, generally, using the Jordan normal form) the matrix.

MatrixPower[A,10000]//N

Matrices as linear operators. Rotation matrices.

A very common way to visualize 3D images is by drawing a set of small triangles. Such images can be described by two matrices.
A matrix containing the points of the image (we shall denote it with dataVert) and a matrix containing the indices of the points
that define the triangles (we shall denote it with dataPoly).

ExampleData[{"Geometry3D","SpaceShuttle"}]

dataVert=ExampleData[{"Geometry3D","SpaceShuttle"},"VertexData"];
dataPoly=ExampleData[{"Geometry3D","SpaceShuttle"},"PolygonData"];

Given the two matrices dataVert and dataPoly, we can reassemble the image in the following way.

Graphics3D[GraphicsComplex[dataVert,Polygon[dataPoly]],AxesLabel->{"x","y","z"},Axes->True]

Exercise 3: Rotate the given image about the x-axis, the y-axis. Make compositions of two rotations - about the x-axis and then the y-axis; about the y-axis and then the x-axis. Visualize the results in a row.

GraphicsRow[{Graphics3D[GraphicsComplex[Table[{{1,0,0},{0,Cos[Pi/3],-Sin[Pi/3]},{0,Sin[Pi/3],Cos[Pi/3]}}.dataVert[[i]],{i,1,Length[dataVert]}],Polygon[dataPoly]],AxesLabel->{"x","y","z"},Axes->True],
Graphics3D[GraphicsComplex[Table[{{Cos[Pi/3],-Sin[Pi/3],0},{Sin[Pi/3],Cos[Pi/3],0},{0,0,1}}.dataVert[[i]],{i,1,Length[dataVert]}],Polygon[dataPoly]],AxesLabel->{"x","y","z"},Axes->True],
Graphics3D[GraphicsComplex[Table[{{Cos[Pi/3],-Sin[Pi/3],0},{Sin[Pi/3],Cos[Pi/3],0},{0,0,1}}.{{1,0,0},{0,Cos[Pi/3],-Sin[Pi/3]},{0,Sin[Pi/3],Cos[Pi/3]}}.dataVert[[i]],{i,1,Length[dataVert]}],Polygon[dataPoly]],AxesLabel->{"x","y","z"},Axes->True],
Graphics3D[GraphicsComplex[Table[{{1,0,0},{0,Cos[Pi/3],-Sin[Pi/3]},{0,Sin[Pi/3],Cos[Pi/3]}}.{{Cos[Pi/3],-Sin[Pi/3],0},{Sin[Pi/3],Cos[Pi/3],0},{0,0,1}}.dataVert[[i]],{i,1,Length[dataVert]}],Polygon[dataPoly]],AxesLabel->{"x","y","z"},Axes->True]}]