advanced-mathematical-formulas
Advanced Mathematical Formulas
The previous chapter solved single-line formulas; this chapter handles the "heavyweights": matrices, systems of equations, multi-line derivations, and formula numbering.
They all come from the amsmath package—which is why every math document should have a line \usepackage{amsmath} in its preamble.
Matrices: The matrix Family
Matrices use environments: & separates columns, \\ starts a new line, and the environment name determines the outer bracket style.
| Environment | Outer Style | Typical Use |
|---|---|---|
matrix | No brackets | Concatenating data blocks |
pmatrix | Parentheses () | Ordinary matrices |
bmatrix | Square brackets [] | Coefficient matrices, linear algebra |
Bmatrix | Curly braces {} | Set notation |
vmatrix | Single vertical bars | | | Determinants |
Vmatrix | Double vertical bars || || | Norms |
pmatrix (parenthesized matrix)
\[
\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}
\]
bmatrix (bracketed matrix)
\[
\begin{bmatrix}
1 & 0 \\
0 & 1
\end{bmatrix}
\]
vmatrix (determinant)
\[
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
= ad - bc
\]
Example: n-th Order Matrix with Ellipsis
\[
\begin{pmatrix}
a_{11} & \cdots & a_{1n} \\
\vdots & \ddots & \vdots \\
a_{n1} & \cdots & a_{nn}
\end{pmatrix}
\]
The three ellipsis commands have distinct roles: \cdots horizontal, \vdots vertical, \ddots diagonal. When matrix elements are numerous, always use ellipsis instead of typing dozens of elements.
When a large matrix does not fit inline, use the smallmatrix environment, which compresses line spacing and font size.
Multi-line Derivations: The align Environment
align is the main environment for mathematical derivations: multi-line formulas are aligned at positions marked by &, and each line is automatically numbered.
Example: Two-line Derivation
\begin{align}
(a+b)^2 &= a^2 + 2ab + b^2 \\
&= a^2 + b^2 + 2ab
\end{align}
There are only two rules: place & at the "alignment anchor" (usually before the equals sign), which splits the line into two columns; and \\ for line breaks. Each line automatically receives a number.
Example: Definite Integral Calculation
\begin{align}
\int_0^1 x^2 \,\mathrm{d}x
&= \left[ \frac{x^3}{3} \right]_0^1 \notag \\[2pt]
&= \frac{1}{3}
\end{align}
Two new constructs appear here: \notag suppresses numbering for a line (use it for intermediate derivation steps that do not need numbers); [2pt] after \\ fine-tunes line spacing and can be omitted.
When no numbering is needed at all, use the starred
align*environment—this follows the same logic as the section command\section*: the star means "unnumbered, not in the table of contents."
Systems of Equations and Piecewise Functions: The cases Environment
The cases environment specifically generates a grouped structure with a large brace on the left; it is the standard way to write systems of equations and piecewise functions.
Example: System of Two Linear Equations
\[
\begin{cases}
x + y = 5 \\
2x - y = 1
\end{cases}
\]
Example: Piecewise Function
\[
f(x) =
\begin{cases}
-x, & x < 0 \\
x, & x \ge 0
\end{cases}
\]
In piecewise functions, the role of & changes: it splits the line into two columns, "function value" and "condition," with the second column automatically right-aligned.
Formula Numbering and Referencing
Display formulas \[...\] are unnumbered; formulas that need to be referenced use the equation environment, which numbers them automatically.
Example: Numbering and Referencing
\documentclass{ctexart}
\usepackage{amsmath}
\begin{document}
From Eq.~\eqref{eq:pyth}, the hypotenuse of a right triangle satisfies
\begin{equation}\label{eq:pyth}
a^2 + b^2 = c^2,
\end{equation}
and the sum of the first $n$ terms of an arithmetic sequence is
\begin{equation}\label{eq:sum}
S_n = \frac{n(a_1 + a_n)}{2}.
\end{equation}
\end{document}
From Eq. (1), the hypotenuse of a right triangle satisfies
And the sum of the first terms of an arithmetic sequence is
The two formulas are automatically numbered (1) and (2); when referencing, use \eqref{key} to get the number in parentheses.
Three steps to remember: equation handles numbering, \label{key} tags the formula, and \eqref{key} references it (automatically with parentheses).
For label names, the suggestion is [type:content], such as eq:pyth, eq:sum—when there are many formulas, names like eq:3 reduce readability.
A reference showing
??means the aux file has not been updated; compile again.
Breaking Long Formulas: The split Environment
When a single formula is too long for the page width, put it inside equation and use split to break it—the whole formula keeps a single number.
\begin{equation}
\begin{split}
\sum_{i=1}^n (x_i - \bar{x})(y_i - \bar{y})
&= \sum_{i=1}^n x_i y_i - n\bar{x}\bar{y} \\
&= \frac{1}{n}\sum_{i=1}^n x_i y_i - \bar{x}\bar{y}
\end{split}
\end{equation}
The difference between split and align: align is multiple formulas, each with its own number; split is one formula split into several lines, sharing one number. split must live inside equation (or \[...\]).
Common Formula Error Troubleshooting
Math-mode errors account for a large share of beginner errors. High-frequency errors are as follows:
| Incorrect Syntax | Problem | Correct Syntax |
|---|---|---|
Using \alpha directly in text | Math commands can only be used in math mode | |
Missing content after _ or ^ | Add it: | |
\dfrac | Using \dfrac without loading amsmath | Add \usepackage{amsmath} in preamble |
\a & b \\ c & d | Using & in an ordinary display formula | & belongs only to matrix, align, etc. |
| Chinese explanations inside formulas | Fonts and line breaks become messed up | Put explanations outside $ $, or use \text{...} |
Forgetting \\ in align | Multiple lines squeezed into one | Add \\ at the end of each line (except the last) |
The \text{...} command is provided by the amsmath package. It is explained separately here: when a small amount of text needs to be embedded inside a mathematical formula (e.g., condition descriptions like "when (x>0)", physical units, etc.), use \text{} to wrap the text. This keeps the text upright and maintains reasonable character spacing.
Summary
| Need | Environment / Command |
|---|---|
| Matrix | pmatrix / bmatrix / vmatrix (& for columns, \\ for rows) |
| Multi-line derivation (numbered per line) | align, starred version unnumbered |
| System of equations / piecewise function | cases |
| Single numbered formula | equation + \label |
| Reference formula number | \eqref{key} |
| Long formula break | split inside equation |