Skip to main content

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.

EnvironmentOuter StyleTypical Use
matrixNo bracketsConcatenating data blocks
pmatrixParentheses ()Ordinary matrices
bmatrixSquare brackets []Coefficient matrices, linear algebra
BmatrixCurly braces {}Set notation
vmatrixSingle vertical bars | |Determinants
VmatrixDouble vertical bars || ||Norms

pmatrix (parenthesized matrix)

\[
\begin{pmatrix}
1 & 2 \\
3 & 4
\end{pmatrix}
\]
(1234)\begin{pmatrix} 1 & 2 \\ 3 & 4 \end{pmatrix}

bmatrix (bracketed matrix)

\[
\begin{bmatrix}
1 & 0 \\
0 & 1
\end{bmatrix}
\]
[1001]\begin{bmatrix} 1 & 0 \\ 0 & 1 \end{bmatrix}

vmatrix (determinant)

\[
\begin{vmatrix}
a & b \\
c & d
\end{vmatrix}
= ad - bc
\]
abcd=adbc\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}
\]
(a11a1nan1ann)\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}
(a+b)2=a2+2ab+b2=a2+b2+2ab\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}
01x2dx=[x33]01=13\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}
\]
{x+y=52xy=1\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}
\]
f(x)={x,x<0x,x0f(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

a2+b2=c2(1)a^2 + b^2 = c^2 \tag{1}

And the sum of the first nn terms of an arithmetic sequence is

Sn=n(a1+an)2(2)S_n = \frac{n(a_1 + a_n)}{2} \tag{2}

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}
i=1n(xixˉ)(yiyˉ)=i=1nxiyinxˉyˉ=1ni=1nxiyixˉyˉ\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 SyntaxProblemCorrect Syntax
Using \alpha directly in textMath commands can only be used in math modeα\alpha
a1+ba - 1 + bMissing content after _ or ^Add it: a1+b2a_1 + b^2
\dfracUsing \dfrac without loading amsmathAdd \usepackage{amsmath} in preamble
\a & b \\ c & dUsing & in an ordinary display formula& belongs only to matrix, align, etc.
Chinese explanations inside formulasFonts and line breaks become messed upPut explanations outside $ $, or use \text{...}
Forgetting \\ in alignMultiple lines squeezed into oneAdd \\ 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

NeedEnvironment / Command
Matrixpmatrix / bmatrix / vmatrix (& for columns, \\ for rows)
Multi-line derivation (numbered per line)align, starred version unnumbered
System of equations / piecewise functioncases
Single numbered formulaequation + \label
Reference formula number\eqref{key}
Long formula breaksplit inside equation