Compact, elegant, and powerful—matrices organize systems of equations into structured arrays. Essential for linear transformations, computation, and data representation. 🧮
Matrix Notation
Suppose we have the following system of linear equations:
\[
\begin{aligned}
2x_1 - x_2 + x_3 &= 8 \\
x_1 &= 2 \\
4x_3 &= 7
\end{aligned}
\]
We can compactly record the essential information of a linear system in a array called a coefficient matrix :
\[
\begin{bmatrix}
2 & -1 & 1 \\
1 & 0 & 0 \\
0 & 0 & 4
\end{bmatrix}
\]
This matrix is a squared matrix with dimensions \(n\) x \(n\) . Since the matrix has the same number rows (\(3\) ) as it has columns (\(3\) ).
If constants were known, we can also represent them in a augmented matrix :
\[
\begin{bmatrix}
2 & -1 & 1 & 8\\
1 & 0 & 0 & 2\\
0 & 0 & 4 & 7
\end{bmatrix}
\]
This matrix is a rectangular matrix with dimensions \(m\) x \(n\) . Since the array has the different number rows (\(3\) ) and columns (\(4\) ).
In data science, it’s common for the constants (outputs) to be unknown or variable. As a result, when we refer to matrices , we’re usually talking about the coefficient matrix.
A more general notation for a matrix denoted \(A\) is
\[
A = \begin{bmatrix}
a_{11} & a_{12} & \cdots & a_{1n} \\
a_{21} & a_{22} & \cdots & a_{2n} \\
\vdots & \vdots & \ddots & \vdots \\
a_{m1} & a_{m2} & \cdots & a_{mn}
\end{bmatrix}
\]
viewof a11 = Inputs. range ([- 10 , 10 ], {
step : 1 ,
value : 2 ,
label : tex `a_{11}` ,
width : 200
})
viewof a12 = Inputs. range ([- 10 , 10 ], {
step : 1 ,
value : 3 ,
label : tex `a_{12}` ,
width : 200
})
viewof a21 = Inputs. range ([- 10 , 10 ], {
step : 1 ,
value : 1 ,
label : tex `a_{21}` ,
width : 200
})
viewof a22 = Inputs. range ([- 10 , 10 ], {
step : 1 ,
value : - 2 ,
label : tex `a_{22}` ,
width : 200
})
// Display matrix equation Ax = 0
html `<div style="text-align: center; font-size: 1.3em; margin: 2em 0;">
<p style="margin-top: 1em;">
${ tex `A = \b egin{bmatrix} ${ a11} & ${ a12} \\ ${ a21} & ${ a22} \e nd{bmatrix}` }
</p>
</div>`
matrixSolution = {
// Calculate determinant
const det = a11 * a22 - a12 * a21;
if (Math . abs (det) < 1e-10 ) {
return { status : "Infinite solutions (non-trivial)" , x1 : null , x2 : null , det, inverse : null };
} else {
// For homogeneous systems with non-zero determinant, only trivial solution exists
return { status : "Unique solution (trivial)" , x1 : 0 , x2 : 0 , det, inverse : null };
}
}
// Generate points for first line (a11*x + a12*y = 0)
points1 = {
const result = [];
for (let i = 0 ; i < 200 ; i++ ) {
const x = i / 10 - 10 ;
if (a12 !== 0 ) {
const y = - (a11 * x) / a12;
if (y >= - 10 && y <= 10 ) {
result. push ({x, y});
}
}
}
return result;
}
// Generate points for second line (a21*x + a22*y = 0)
points2 = {
const result = [];
for (let i = 0 ; i < 200 ; i++ ) {
const x = i / 10 - 10 ;
if (a22 !== 0 ) {
const y = - (a21 * x) / a22;
if (y >= - 10 && y <= 10 ) {
result. push ({x, y});
}
}
}
return result;
}
// Create the plot
Plot. plot ({
style : "overflow: visible; display: block; margin: 0 auto;" ,
width : 500 ,
height : 400 ,
grid : true ,
x : {label : "x₁" , domain : [- 10 , 10 ]},
y : {label : "x₂" , domain : [- 10 , 10 ]},
marks : [
Plot. ruleY ([0 ]),
Plot. ruleX ([0 ]),
Plot. line (points1, {
x : "x" ,
y : "y" ,
stroke : "steelblue" ,
strokeWidth : 2
}),
Plot. line (points2, {
x : "x" ,
y : "y" ,
stroke : "crimson" ,
strokeWidth : 2
}),
matrixSolution. x1 !== null ? Plot. dot ([{x : matrixSolution. x1 , y : matrixSolution. x2 }], {
x : "x" ,
y : "y" ,
r : 6 ,
fill : "black" ,
stroke : "white" ,
strokeWidth : 2
}) : null
]
})