In this example we will show how to solve simple linear algebra problems such as finding the determinant, matrix multiplication and SVG factorisation.
First of all, please run the preparatory code cell.
Finding the determinant of a matrix¶
Find the determinant of the matrix $\left [ \begin{array}{cc}1 & 2 & 3 \\4 & 1 & 6 \\ 7 & 8 & 1 \end{array} \right ]$
Matrix multiplication¶
Find the coordinates of the point (1,2,0) when rotated about the Z axis by the angle $90^{\circ}$.
[-2.0, 1.0000000000000002, 0.0]
Reducing the dimensionality of a matrix through factorisation¶
A feature matrix of three objects is given:
$A = \left [ \begin{array}{cc}1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10\\
11 & 12 & 13 & 14 & 15 & 16 & 17 & 18 & 19 & 20\\
21 & 22 & 23 & 24 & 25 & 26 & 27 & 28 & 29 & 30 \end{array} \right ]$
The columns contain the features of the objects, but they contain redundant information. Perform dimensionality reduction to two variables using SVD and additional operations. Specific steps of the algorithm:
- Decompose the matrix into components
U, s, VT
using the function svd()
.
- Create a null matrix
Sigma
of the same size as the matrix A
, and fill its main diagonal with the elements of the vector S
.
- Separate 2 columns of the matrix
Sigma
and 2 rows of the matrix V
to find the projection of the matrix into the reduced dimension space using the commands T = U * Sigma
.
Out[0]:
3×2 Matrix{Float64}:
-18.5216 6.47697
-49.8131 1.91182
-81.1046 -2.65333
Out[0]:
3×3 Matrix{Float64}:
2.80454 7.16027 12.4563
11.5326 25.8784 22.6968
20.2608 44.5964 32.9373
{"id": "44d99da5-ee4e-4124-a6b2-e7e4570582fb", "data": [{"xaxis": "x", "mode": "markers", "x": [1], "showlegend": true, "name": "y1", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": [0], "legendgroup": "y1", "y": [2], "zaxis": "z", "zmax": null, "scene": "scene", "yaxis": "y", "marker": {"line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "size": 8}, "type": "scatter3d"}], "config": {"showlegend": false, "height": 500, "annotations": [], "scene": {"zaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.00", "0.25", "0.50", "0.75", "1.00"], "range": [-0.030000000000000027, 1.03], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.25, 0.5, 0.75, 1], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectratio": {"x": 1, "z": 1, "y": 1}, "camera": {"eye": {"x": 1.2883056996112483, "z": 1.0285409634817124, "y": -1.5101087427261743}, "center": {"x": 0, "z": 0, "y": 0}, "projection": {"type": "perspective"}, "up": {"x": 0, "z": 1, "y": 0}}, "xaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["-1", "0", "1", "2"], "range": [-1.073132491389208, 2.0731324913892077], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [-1, 0, 1, 2], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "domain": {"x": [0.05100612423447075, 0.9934383202099736], "y": [0.03762029746281716, 0.9901574803149606]}, "yaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.0", "0.5", "1.0", "1.5", "2.0"], "range": [-0.06000000000000005, 2.06], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.5, 1, 1.5, 2], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectmode": "auto"}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "margin": {"t": 20, "b": 20, "r": 0, "l": 0}, "width": 736.640625}}
{"id": "8f726af1-0bb6-4751-8ebe-61bf140dd593", "data": [{"xaxis": "x", "mode": "markers", "x": [1], "showlegend": true, "name": "y1", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": [0], "legendgroup": "y1", "y": [2], "zaxis": "z", "zmax": null, "scene": "scene", "yaxis": "y", "marker": {"line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "symbol": "circle", "color": "rgba(0, 154, 250, 1.000)", "size": 8}, "type": "scatter3d"}, {"xaxis": "x", "mode": "markers", "x": [-2], "showlegend": true, "name": "y2", "colorbar": {"title": {"text": ""}}, "zmin": null, "z": [0], "legendgroup": "y2", "y": [1.0000000000000002], "zaxis": "z", "zmax": null, "scene": "scene", "yaxis": "y", "marker": {"line": {"color": "rgba(0, 0, 0, 1)", "width": 1}, "symbol": "circle", "color": "rgba(227, 111, 71, 1.000)", "size": 8}, "type": "scatter3d"}], "config": {"showlegend": false, "height": 500, "annotations": [], "scene": {"zaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.00", "0.25", "0.50", "0.75", "1.00"], "range": [-0.030000000000000027, 1.03], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.25, 0.5, 0.75, 1], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectratio": {"x": 2.0800838230519045, "z": 0.6933612743506348, "y": 0.6933612743506347}, "camera": {"eye": {"x": 1.9715572022580123, "z": 1.0344963371896456, "y": -1.3426762553071998}, "center": {"x": 0, "z": 0, "y": 0}, "projection": {"type": "perspective"}, "up": {"x": 0, "z": 1, "y": 0}}, "xaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["-2", "-1", "0", "1"], "range": [-2.09, 1.09], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [-2, -1, 0, 1], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "domain": {"x": [0.05100612423447069, 0.9934383202099737], "y": [0.03762029746281716, 0.9901574803149606]}, "yaxis": {"showline": false, "gridcolor": "rgba(0, 0, 0, 0.1)", "showticklabels": true, "tickfont": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 11}, "tickmode": "array", "ticktext": ["0.0", "0.5", "1.0", "1.5", "2.0"], "range": [-0.07136557742294825, 2.0713655774229482], "tickcolor": "rgba(0, 0, 0, 0)", "gridwidth": 0.5, "visible": true, "tickvals": [0, 0.5, 1, 1.5, 2], "showgrid": true, "linecolor": "rgba(0, 0, 0, 1)", "zerolinecolor": "rgba(0, 0, 0, 1)", "tickangle": 0, "zeroline": true, "mirror": false, "title": {"font": {"family": "sans-serif", "color": "rgba(0, 0, 0, 1)", "size": 15}, "text": ""}, "ticks": "inside", "type": "linear"}, "aspectmode": "auto"}, "plot_bgcolor": "rgba(255, 255, 255, 1.000)", "paper_bgcolor": "rgba(255, 255, 255, 1.000)", "margin": {"t": 20, "b": 20, "r": 0, "l": 0}, "width": 736.640625}}