Mathematical guide/Matrix operations: Difference between revisions

From Xenharmonic Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 6: Line 6:
\end{pmatrix} </math>.
\end{pmatrix} </math>.


The dot product is a way to combine two vectors to get out a single number.  
The dot product is a way to combine two vectors to get out a single number. Say we want to take the dot product of the vectors <math> \begin{pmatrix}12\\19\\28\end{pmatrix} </math> and <math> \begin{pmatrix}-2\\0\\1\end{pmatrix} </math>. To do so, follow these steps:
Say we want to take the dot product of the vectors <math> \begin{pmatrix}12\\19\\28\end{pmatrix} </math> and <math> \begin{pmatrix}-2\\0\\1\end{pmatrix} </math>.
 
To do so, follow these steps:
* Write the vectors separated by a dot to denote the dot product: <math>
* Write the vectors separated by a dot to denote the dot product: <math>
\begin{pmatrix}
\begin{pmatrix}
Line 21: Line 20:
1
1
\end{pmatrix}
\end{pmatrix}
</math>  
</math>
**This may also be notated <math> \langle 12, 19, 28 \vert -2, 0, 1\rangle </math>; from this derives the notation for vals and monzos.  
** This may also be notated <math> \langle 12, 19, 28 \vert -2, 0, 1\rangle </math>; from this derives the notation for vals and monzos.
* Multiply the corresponding elements, and add the results together: <math> \left(12\cdot-2\right)+\left(19\cdot0\right)+\left(28\cdot1\right) = -24 + 0 + 28 = 4 </math>
* Multiply the corresponding elements, and add the results together: <math> \left(12\cdot-2\right)+\left(19\cdot0\right)+\left(28\cdot1\right) = -24 + 0 + 28 = 4 </math>


Line 53: Line 52:
where the second object is the vector.
where the second object is the vector.


To write the first element of our output, we take the dot product of the first row of our matrix with our vector:
To write the first element of our output, we take the dot product of the first row of our matrix with our vector: <math>\begin{pmatrix}
<math>\begin{pmatrix}
1\\
1\\
0\\
0\\
Line 85: Line 83:
-6\\
-6\\
4\\
4\\
\end{bmatrix}</math>
\end{bmatrix}</math> .
.


== Multiply matrix by matrix ==
== Multiply matrix by matrix ==
A matrix can act on another matrix, as well. In this case, the matrix on the right can simply be treated as several vectors next to each other.
A matrix can act on another matrix, as well. In this case, the matrix on the right can simply be treated as several vectors next to each other.


<math>
<math>
Line 109: Line 104:
\end{bmatrix}
\end{bmatrix}
</math>
</math>
== Determinant ==
todo
== Practical usage ==
Let's say we want to determine the tuning of 6/5 in quarter-comma meantone.
=== Stage 1: JI to temperament ===
<math>
\begin{bmatrix}
1 & 0 & -4\\
0 & 1 & 4
\end{bmatrix}
</math>
This matrix I've been using as an example is actually a "function" that converts a 5-limit interval in monzo format (with the entries corresponding to powers of 2, 3, and 5) into a corresponding meantone interval in an analogous format (with the entries representing powers of meantone's tempered 2 and 3) called "tempered monzos" or "tmonzos".
So, let's take the monzo for 6/5, [1 1 -1⟩, and apply this matrix to it: <math>
\begin{bmatrix}
1 & 0 & -4\\
0 & 1 & 4
\end{bmatrix}
\begin{bmatrix}
1\\
1\\
-1
\end{bmatrix}
=
\begin{bmatrix}
5\\
-3
\end{bmatrix}</math>.
The result is the meantone tmonzo representing a tempered 6/5.
=== Stage 2: Temperament to tuning ===
Now, we have the tmonzo. We'll be introducing something called a tval, which gives us a specific tuning of our temperament the same way a regular val gives us a specific tuning of just intonation. The quarter-comma meantone tval for this meantone mapping is ⟨1200 ~1896.5784] in cents. This is where the dot product comes in: <math> \langle 1200, ~1896.5784 \vert 5, -3\rangle </math>.
Computing this dot product yields ~310.265, which is exactly the size of the QCM minor third in cents!

Revision as of 05:49, 14 April 2025

Dot product

A vector is a list of numbers, written like so: [math]\displaystyle{ \begin{pmatrix} -2\\ 0\\ 1 \end{pmatrix} }[/math].

The dot product is a way to combine two vectors to get out a single number. Say we want to take the dot product of the vectors [math]\displaystyle{ \begin{pmatrix}12\\19\\28\end{pmatrix} }[/math] and [math]\displaystyle{ \begin{pmatrix}-2\\0\\1\end{pmatrix} }[/math]. To do so, follow these steps:

  • Write the vectors separated by a dot to denote the dot product: [math]\displaystyle{ \begin{pmatrix} 12\\ 19\\ 28\\ \end{pmatrix} \cdot \begin{pmatrix} -2\\ 0\\ 1 \end{pmatrix} }[/math]
    • This may also be notated [math]\displaystyle{ \langle 12, 19, 28 \vert -2, 0, 1\rangle }[/math]; from this derives the notation for vals and monzos.
  • Multiply the corresponding elements, and add the results together: [math]\displaystyle{ \left(12\cdot-2\right)+\left(19\cdot0\right)+\left(28\cdot1\right) = -24 + 0 + 28 = 4 }[/math]

Multiply matrix by vector

A matrix is a grid of numbers, written like so:

[math]\displaystyle{ \begin{bmatrix} 1 & 0 & -4\\ 0 & 1 & 4 \end{bmatrix} }[/math]

This matrix can be thought of as a "function" that you apply to a vector to get out another vector. This matrix has 3 columns, meaning the vector it takes as an "input" will have 3 elements, and it has 2 rows, meaning the vector you get out will have 2 elements. So, this is a "function" down from 3-dimensional space to 2-dimensional space.

We write this "application" of a matrix like so:

[math]\displaystyle{ \begin{bmatrix} 1 & 0 & -4\\ 0 & 1 & 4 \end{bmatrix} \begin{bmatrix} -2\\ 0\\ 1 \end{bmatrix} }[/math]

where the second object is the vector.

To write the first element of our output, we take the dot product of the first row of our matrix with our vector: [math]\displaystyle{ \begin{pmatrix} 1\\ 0\\ -4\\ \end{pmatrix} \cdot \begin{pmatrix} -2\\ 0\\ 1 \end{pmatrix} = \left(1\cdot-2\right)+\left(0\cdot0\right)+\left(-4\cdot1\right) = -2 + 0 + -4 = -6 }[/math]

We do the same thing for the second element of our output, computing [math]\displaystyle{ \begin{pmatrix} 0\\ 1\\ 4\\ \end{pmatrix} \cdot \begin{pmatrix} -2\\ 0\\ 1 \end{pmatrix} = 4 }[/math].

Thus, our output is [math]\displaystyle{ \begin{bmatrix} -6\\ 4\\ \end{bmatrix} }[/math] .

Multiply matrix by matrix

A matrix can act on another matrix, as well. In this case, the matrix on the right can simply be treated as several vectors next to each other.

[math]\displaystyle{ \begin{bmatrix} 1 & 0 & -4\\ 0 & 1 & 4 \end{bmatrix} \begin{bmatrix} 1 & -1 & -2\\ 0 & 1 & 0\\ 0 & 0 & 1 \end{bmatrix} = \begin{bmatrix} 1 & -1 & -6\\ 0 & 1 & 4 \end{bmatrix} }[/math]

Determinant

todo

Practical usage

Let's say we want to determine the tuning of 6/5 in quarter-comma meantone.

Stage 1: JI to temperament

[math]\displaystyle{ \begin{bmatrix} 1 & 0 & -4\\ 0 & 1 & 4 \end{bmatrix} }[/math]

This matrix I've been using as an example is actually a "function" that converts a 5-limit interval in monzo format (with the entries corresponding to powers of 2, 3, and 5) into a corresponding meantone interval in an analogous format (with the entries representing powers of meantone's tempered 2 and 3) called "tempered monzos" or "tmonzos".

So, let's take the monzo for 6/5, [1 1 -1⟩, and apply this matrix to it: [math]\displaystyle{ \begin{bmatrix} 1 & 0 & -4\\ 0 & 1 & 4 \end{bmatrix} \begin{bmatrix} 1\\ 1\\ -1 \end{bmatrix} = \begin{bmatrix} 5\\ -3 \end{bmatrix} }[/math].

The result is the meantone tmonzo representing a tempered 6/5.

Stage 2: Temperament to tuning

Now, we have the tmonzo. We'll be introducing something called a tval, which gives us a specific tuning of our temperament the same way a regular val gives us a specific tuning of just intonation. The quarter-comma meantone tval for this meantone mapping is ⟨1200 ~1896.5784] in cents. This is where the dot product comes in: [math]\displaystyle{ \langle 1200, ~1896.5784 \vert 5, -3\rangle }[/math].

Computing this dot product yields ~310.265, which is exactly the size of the QCM minor third in cents!