# MathJax basic tutorial and quick reference


Second, add \limits_{x \to 1} inside. The code now looks like $\lim \limits_{x \to 1}$, and renders as $\lim \limits_{x \to 1}$. The \to inside makes the right arrow, rendered as $\to$. The _ makes the $x \to 1$ go underneath the $\lim$. Finally, the pair of curly braces { } makes sure that $x \to 1$ is treated as a whole object, and not two separate things.

Lastly, add the function you want to apply the limit to. To make the limit mentioned above, $\lim \limits_{x \to 1} \frac{x^2-1}{x-1}$, simply use $\lim\limits_{x \to 1} \frac{x^2-1}{x-1}$.

And that is how you make a limit using MathJax.

• Why not just \lim_{x\to 1} $$\lim_{x\to 1}?$$ As I understand it \limits is only needed for operations that don't already understand limits, for example if you want to use + and get $$\mathop{+}\limits_{i=1}^k\text{ instead of }+_{i=1}^k$$ When used inline, your suggestion will produce $\lim\limits_{x\to 1}$ instead of the more compact form $\lim_{x\to 1}$ that mathjax normally chooses. Are you sure this is good advice? – MJD Feb 26 '14 at 14:10
• @MJD $\lim_{x\to 1} renders to$\lim_{x\to 1}$, and$\lim\limits_{x\to 1 renders as $lim\limits_{x\to 1}$. Note how the $x\to 1$ is separated from the first limit, and not directly underneath. We do not write limits like that in real life, so we use \limits. – TrueDefault Feb 26 '14 at 16:19
• I meant that the second limit renders to $\lim \limits_{x \to 1}$ – TrueDefault Feb 26 '14 at 16:28
• Limits are usually written that way in typeset materials like papers and books when the limit is inline, rather than a displayed formula, and that's why MathJax typesets it that way. – MJD Feb 26 '14 at 16:41
• The issue with this answer is that it is trying to "force" display mode on inline code. Doing so makes the text look less pretty. For example, see how the spacing between the lines change when I force display mode using \lim\limits_{x\mapsto 1}\dfrac1x: $\lim\limits_{x\mapsto 1}\dfrac1x$. On the other hand, when I let $\TeX$ do what it wants to do, using \lim_{x\mapsto 1}\frac1x, the spacing between the lines stays the same, which is much neater: $\lim_{x\mapsto 1}\frac1x$. This is much easier on the eyes. If you want to make your math mode more prominent then take a new line using $$-$$ – user1729 Jul 17 '14 at 12:30
• The moral is: $\TeX$ was written by a jolly clever chap. Let it do what it wants, because it does it for a reason! – user1729 Jul 17 '14 at 12:35
• Part 11 of the "question" shows how to write limits in the way they were meant to be written in LaTeX and MathJax. – David K Nov 14 '15 at 23:17

# Absolute values and norms

The absolute value of some expression can be denoted as \lvert x\rvert or, more generally, as \left\lvert … \right\rvert. It renders as $\lvert x\rvert$.

The norm of a vector (or similar) can be denoted as \lVert v\rVert or, more generally, as \left\lVert … \right\rVert. It renders as $\lVert v\rVert$. (You may also write \left\|…\right\| instead.)

In both cases, the rendering is better than what you'd get from |x| or ||v||, which render with bars that don't descend low enough and sub-optimal spacing. At least on some browsers, so here is a screenshot how it looks for me, using Firefox 31 on OS X:

And here is the same formula rendered by your browser:

$$|x|, ||v|| \quad\longrightarrow\quad \lvert x\rvert, \lVert v\rVert$$

It was typeset as

$$|x|, ||v|| \quad\longrightarrow\quad \lvert x\rvert, \lVert v\rVert$$
• You can use \|x\| instead of \lVert x \rVert; $\|x\|$ and $\lVert x \rVert$. (I don't think that there is a difference between them. I've tried [asking on SE](tex.stackexchange.com/questions/77767/whats-the-correct-way-to-write-norm).) – Martin Sleziak Jun 24 '14 at 8:48
• On my browser |x| and \lvert x\rvert ($|x|$ and $\lvert x\rvert$) look identical, contrary to your claim. Perhaps you need to show an example more complicated than just 'x'? – MJD Jun 24 '14 at 12:39
• @MJD: What's your browser? I included a screenshot to support my claim. – MvG Aug 13 '14 at 11:24
• Usually various versions of Firefox on either Linux or Windows. I happen to have Windows 8 booted now, so here's a screenshot from there: a.pomf.se/jrujkq.PNG The bar height looks good on both pairs of symbols; the spacing is a little off for the || version. On Linux they looked the same. – MJD Aug 13 '14 at 17:02
• Here's a screenshot with FF 31.0 under Linux: a.pomf.se/fhwmjo.png – MJD Aug 16 '14 at 6:23
• The difference in output that you are seeing has to do with whether you have the STIX fonts installed locally on your computer or not. The | in STIX doesn't descend below the baseline, while in the MathJax TeX fonts it does. – Davide Cervone May 20 '16 at 14:16

# Highlighting equation

To highlight an equation, \bbox can be used. E.g,

$$\bbox[yellow] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) }$$

produces

$$\bbox[yellow] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) }$$

By default, the bounding box is "tight", so it doesn't extend beyond the characters used in the formula. You can add a little space around the equation by adding a measurement after the color. E.g.,

$$\bbox[yellow,5px] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) }$$

produces

$$\bbox[yellow,5px] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) }$$

To add a border, use

$$\bbox[5px,border:2px solid red] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (2) }$$

produces

$$\bbox[5px,border:2px solid red] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (2) }$$

You can do both border and background, as well:

$$\bbox[yellow,5px,border:2px solid red] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) }$$

produces

$$\bbox[yellow,5px,border:2px solid red] { e^x=\lim_{n\to\infty} \left( 1+\frac{x}{n} \right)^n \qquad (1) }$$

• When using constructs like this, please heed the points raised in this discussion on usage of colour. – Lord_Farin May 20 '16 at 15:56
• This would be a very helpful feature. – Always Confused May 19 '17 at 13:36

## Giving reasons on each line of a sequence of equations

To produce this: \begin{align} v + w & = 0 &&\text{Given} \tag 1\\ -w & = -w + 0 && \text{additive identity} \tag 2\\ -w + 0 & = -w + (v + w) && \text{equations $(1)$ and $(2)$} \end{align}

write this:

\begin{align}
v + w & = 0  &&\text{Given} \tag 1\\
-w & = -w + 0 && \text{additive identity} \tag 2\\
-w + 0 & = -w + (v + w) && \text{equations $(1)$ and $(2)$}
\end{align}

# Pack of cards

If you are asking (or answering) a combinatorics question involving packs of cards you can make it look more elegant by using \spadesuit, \heartsuit, \diamondsuit, \clubsuit in math mode: $$\spadesuit\quad\heartsuit\quad\diamondsuit\quad\clubsuit$$ Or if you're really fussy:
\color{red}{\heartsuit} and \color{red}{\diamondsuit}
$$\color{red}{\heartsuit}\quad\color{red}{\diamondsuit}$$

You can also enter the standard Unicode characters (U+2660 BLACK SPADE SUIT etc.) literally, or copy them from here:

$$♠\quad♡\quad♢\quad♣\\ ♤\quad♥\quad♦\quad♧$$

• This is very nice! Is there other auto-shapes or stickers? – Always Confused May 19 '17 at 13:37
• Is it also possible to draw the spade and club in outlines and fill the heart and diamond with a colour? – Always Confused May 19 '17 at 13:39
• @AlwaysConfused None that come to mind. Google search turned up this which might help. Otherwise search for a TeX/LaTeX/MathJax symbol table. – David May 22 '17 at 23:48
• @AlwaysConfused Unicode has those characters, so you can enter them however you normally enter Unicode characters, or you can now use copy-paste to copy them from this answer. – MJD May 29 at 16:11
• @MJD Not sure that your edit is a good idea, firstly because I think we would prefer questions and answers on MSE to be in MathJax as far as possible, secondly because this page is specifically a MathJax tutorial. However I'm not really bothered - if you still think it's a good idea, let me know and I'll approve the edit. – David May 30 at 4:31

## Left and Right Implication Arrows

Another way to display the arrows for right and left implication instead of using

$\Rightarrow$, $\Leftarrow$ and $\Leftrightarrow$

which produces $\Rightarrow$, $\Leftarrow$ and $\Leftrightarrow$ respectively, you can use

$\implies$ for $\implies$, $\impliedby$ for $\impliedby$ and $\iff$ for $\iff$

The latter of which produces longer arrows which may be more desirable to some.

## Long division

$$\require{enclose} \begin{array}{r} 13 \\[-3pt] 4 \enclose{longdiv}{52} \\[-3pt] \underline{4}\phantom{2} \\[-3pt] 12 \\[-3pt] \underline{12} \end{array}$$

$$\require{enclose} \begin{array}{r} 13 \\[-3pt] 4 \enclose{longdiv}{52} \\[-3pt] \underline{4}\phantom{2} \\[-3pt] 12 \\[-3pt] \underline{12} \end{array}$$

One important trick shown here is the use of \phantom{2} to make a blank space that is the same size and shape as the digit 2 just above it.

This is adapted from https://stackoverflow.com/a/22871404/3466415 (which uses slightly different but not less valid formatting).

• Synthetic division. Example to find that $$x^3−6x^2+11x−6=(x−{\color{red}1})(x^2−5x+6)+{\color{blue}0}$$ \begin{array}{c|rrrr}& x^3 & x^2 & x^1 & x^0\\ & 1 & -6 & 11 & -6\\ {\color{red}1} & \downarrow & 1 & -5 & 6\\ \hline & 1 & -5 & 6 & |\phantom{-} {\color{blue}0} \end{array} \begin{array}{c|rrrr}& x^3 & x^2 & x^1 & x^0\\ & 1 & -6 & 11 & -6\\ {\color{red}1} & \downarrow & 1 & -5 & 6\\ \hline & 1 & -5 & 6 & |\phantom{-} {\color{blue}0} \end{array} – Américo Tavares Aug 21 '16 at 14:32
• I will need this. It is so useful. – Always Confused May 21 '17 at 16:09
• What about long division? – greedoid Aug 14 at 8:54

# Degree symbol

The degree symbol for angles is not ^\circ. Although many people use this notation, the result looks quite different from the canonical degree symbol shipped with the font:

90° renders as $90°$ while 90^\circ renders as $90^\circ$.

If your keyboard doesn't have a ° key, feel free to copy from this post here, or follow these suggestions.

Note that comments below indicate that on some configurations at least, ° renders inferior to ^\circ. And I recently had a post of mine edited just for the sake of turning ° into ^\circ, indicating that someone felt rather strongly about this. So the suggestion above does seem somewhat controversial at the moment. I maintain that from a semantic point of view, ° is superior to ^\circ, and if the rendering suffers from this, then it's a bug in MathJax. After all, LaTeX offers a proper degree symbol in the tex companion fonts, indicating that someone there, too, decided that ^\circ is not perfect. But if things are broken now, I can't fault people from pragmatically sticking with the rendering they prefer. Personally I prefer semantics, also for the sake of screen readers.

• If mathjax loads siunitx or gensymb, there is then \degree in latex which is the degree symbol. – dustin Feb 17 '15 at 22:29
• @dustin: I couldn't find siunitx or gensymb mentioned anywhere in the MatJax source repository. Are they available as some kind of third-party extension? If so, where? Since MathJax is not LaTeX, packages can't be loaded unless they have been migrated. By the way, all occurrences of “degree” in the MathJax sources refer to something else, as far as I can tell, so there really doesn't seem to be a \degree macro. There should be one, imho. – MvG Feb 17 '15 at 23:39
• I am not a mathjax expert. I just know latex. I just gave that suggestion in case they were available. Siunitx would be a great package to have. If you aren't familiar, you will see the advantage by scanning the documentation on ctan. – dustin Feb 17 '15 at 23:43
• On my display, ° looks bad and ^\circ looks good: a.pomf.se/xnlfyg.png – MJD Mar 24 '15 at 21:10
• Degree sign can generally be typed by holding down Alt and typing 0176 on the numeric keypad. ° (I don't know how international the actual number is). The leading zero is required. – Joffan Apr 19 '17 at 14:04
• @Joffan: 167 is the decimal representation of the Codepoint for ° in Latin 1, Unicode and CP-1252. Without the leading zero, CP-437 gets applied instead, at least in typical English-speaking countries, so you'd use Alt+248 there. The Wikipedia article I linked to already describes those two ways of entering the symbol, and en.wikipedia.org/wiki/Alt_code has some more details. – MvG Apr 20 '17 at 22:24
• How to use Radian (c) , gradian (g) and Steradian (sr) ? And also, Angstrom (though a lenght unit)? – Always Confused May 21 '17 at 16:06
• Actually we can write degrees by 90^o (O for Orange, using lowercase o, like 'o'), and it'd render it close to degrees symbol $$90^o + 30 ^o + 45^o$$ – Abhas Kumar Sinha May 31 at 14:41
• @AbhasKumarSinha It looks quite slanty to me. – Tom Hale Jun 13 at 3:57

# Vertical Spacing

Some formulas such as $\overline a+\overline b=\overline {a\cdot b}$, $\sqrt{a}-\sqrt{b}$, do not look quite right when it comes to vertical spacing. Fortunately, there is more than one way to fix this. One can for instance employ the \mathstrut command as follows:

$\sqrt{\mathstrut a} - \sqrt{\mathstrut b}$

Which yields: $\sqrt{\mathstrut a} - \sqrt{\mathstrut b}$. Or using \vphantom (vertical phantom) command, which measures the height of its argument and places a math strut of that height into the formula.

$\sqrt{\vphantom{b} a} - \sqrt{b}$

Which renders as: $\sqrt{\vphantom{b} a} - \sqrt{b}$.

Another issue is with the spacing within lines in situations like this,

Based on the previous technique, we can simplify $\dfrac{1}{\sqrt{\vphantom{b} a} - \sqrt{b}}$, and we thus get the result of the previous limit.

These two lines are too far apart, but this is unnecessary since the second line is very short. We can solve this by using the \smash command, to get:

Based on the previous technique, we can simplify $\smash{\dfrac{1}{\sqrt{\vphantom{b} a} - \sqrt{b}}}$, and we thus get the result of the previous limit.

# Displaystyle and Textstyle

Many things like fractions, sums, limits, and integrals display differently when written inline versus in a displayed formula. You can switch styles back and forth with \displaystyle and \textstyle in order to achieve the desired appearance.

Here's an example switching back and forth in a displayed equation:

$$\sum_{n=1}^\infty \frac{1}{n^2} \to \textstyle \sum_{n=1}^\infty \frac{1}{n^2} \to \displaystyle \sum_{n=1}^\infty \frac{1}{n^2}$$

$$\sum_{n=1}^\infty \frac{1}{n^2} \to \textstyle \sum_{n=1}^\infty \frac{1}{n^2} \to \displaystyle \sum_{n=1}^\infty \frac{1}{n^2}$$

It is possible to switch style inline as well:

Compare $\displaystyle \lim_{t \to 0} \int_t^1 f(t)\, dt$
versus $\lim_{t \to 0} \int_t^1 f(t)\, dt$.

Compare $\displaystyle \lim_{t \to 0} \int_t^1 f(t)\, dt$ versus $\lim_{t \to 0} \int_t^1 f(t)\, dt$.

• Oh!! I was always confused on why some people had \displaystyle. – Simply Beautiful Art Nov 7 '16 at 0:42

# Mixing code and MathJax formatting on lines

To give an example of how this might be useful, I wanted to express an algorithm in more or less the same indentation and symbolic way it appears in a paper.

On my desktop browsers (Chrome, Firefox) the following appears reasonably well spaced and indented, but loses indentation on my Android smartphone:

Input: positive integer $n$
Output: Tangent numbers $T_1,\ldots,T_n$
$T_1\gets 1$
for$k$ from $2$ to$n$
$T_k\gets (k−1)T_{k−1}$
for$k$ from $2$ to$n$
for$j$ from$k$ to$n$
$T_j\gets (j −k)T_{j−1} + (j −k+2)T_j$
return $\;T_1,T_2,\ldots,T_n$.

The source can be examined for specific techniques, but the basic trick is that a MathJax dollar-delimiter can follow a closing back-tick code delimiter, but an opening back-tick should be preceded by a space when following the (closing) dollar-sign delimiter.

Here is a version using \phantom rather than code monospacing to produce indents and tweaking the spacing between code and MathJax expressions with \;, so that the results appear clear on Android browsers:

Input: positive integer $n$
Output: Tangent numbers $T_1,\ldots,T_n$
$T_1\gets 1$
for $\;k\;$ from $2\;$ to $\;n$
$\phantom{{}++{}}$ $T_k\gets (k−1)T_{k−1}$
for $\;k\;$ from $2\;$ to $\;n$
$\phantom{{}++{}}$ for $\;j\;$ from $\;k\;$ to $\;n$
$\phantom{{}++{}}$ $\phantom{{}++{}}$ $T_j\gets (j −k)T_{j−1} + (j −k+2)T_j$
return $\;T_1,T_2,\ldots,T_n$.

• But this is why we have \space, \quad, and \qquad – Simply Beautiful Art Nov 7 '16 at 0:41
• While those are among the ways $\LaTeX$ provides control over spacing, they do not suffice for mixing code and MathJax formatting on a line. – hardmath Nov 7 '16 at 1:05
• I'm not sure if the topic of mixing other code in is well-suited here. – Simply Beautiful Art Nov 7 '16 at 2:05
• I would write the code in TeX using \texttt if I were you. Regardless, this answer probably does not belong here. – pzp May 21 '17 at 14:10
• @pzp: Thanks, that is an interesting suggestion. – hardmath May 22 '17 at 16:15
• @hardmath you can shorten the <code></code> spacers a bit by writing <codde/>, at least in my Jupyter notebooks in Chrome. – Reb.Cabin Feb 6 at 22:28

# Equation numbering

## simple equation

To give an equation a number, use the \tag{}. To refer to it later, use \label{} to label this equation. When you want to refer to it, use \eqref{}.For example,

$$e=mc^2 \tag{1}\label{eq1}$$

Equation $\eqref{eq1}$ is one the greatest equations in mankind history. Equation $\eqref{eq1}$ is produced using the following code,

$$e=mc^2 \tag{1}\label{eq1}$$

To refer to it, use \eqref{eq1}.

## multi-line equation

Multi-line equation is actually just one equation rather than several equations. So the correct environment is aligned instead of align.

\begin{aligned} a &= b + c \\ &= d + e + f + g \\ &= h + i \end{aligned}\tag{2}\label{eq2}

Equation $\eqref{eq2}$ is a multi-line equation. The code to produce equation $\eqref{eq2}$ is

\begin{aligned} a &= b + c \\ &= d + e + f + g \\ &= h + i \end{aligned}\tag{2}\label{eq2}

## multiple aligned equations

For multiple aligned equations, we use the align environment.

\begin{align} a &= b + c \tag{3}\label{eq3} \\ x &= yz \tag{4}\label{eq4}\\ l &= m - n \tag{5}\label{eq5} \end{align}

Equation $\eqref{eq3}$, $\eqref{eq4}$ and $\eqref{eq5}$ are multiple equations aligned together. The code to produce these equations is,

\begin{align} a &= b + c \tag{3}\label{eq3} \\ x &= yz \tag{4}\label{eq4}\\ l &= m - n \tag{5}\label{eq5} \end{align}
• I don’t believe there is any difference between align and aligned, but whatever feels comfortable I suppose. – user477343 Feb 2 at 6:12
• There is actaully a difference, read here for a detailed discussions. – jdhao Feb 2 at 6:28
• thank you very much for clearing up that understanding :) – user477343 Feb 2 at 6:30
• You are welcome. When in doubt, always google it first :). – jdhao Feb 2 at 6:32

# Linear programminng

## Formulation

A theoretical LPP can be typeset as

\begin{array}{ll}
\text{maximize}  & c^T x \\
\text{subject to}& d^T x = \alpha \\
&0 \le x \le 1.
\end{array}

\begin{array}{ll} \text{maximize} & c^T x \\ \text{subject to}& d^T x = \alpha \\ &0 \le x \le 1. \end{array}

To input a numerical LPP, use alignat instead of align to get better alignment between signs, variables and coefficients.

\begin{alignat}{5}
\max \quad        & z = &   x_1  & + & 12 x_2  &   &       &         && \\
\mbox{s.t.} \quad &     & 13 x_1 & + & x_2     & + & 12x_3 & \geq 5  && \tag{constraint 1} \\
&     & x_1    &   &         & + & x_3   & \leq 16 && \tag{constraint 2} \\
&     & 15 x_1 & + & 201 x_2 &   &       & =    14 && \tag{constraint 3} \\
&     & \rlap{x_i \ge 0, i = 1, 2, 3}
\end{alignat}

\begin{alignat}{5} \max \quad & z = & x_1 & + & 12 x_2 & & & && \\ \mbox{s.t.} \quad & & 13 x_1 & + & x_2 & + & 12x_3 & \geq 5 && \tag{constraint 1} \\ & & x_1 & & & + & x_3 & \leq 16 && \tag{constraint 2} \\ & & 15 x_1 & + & 201 x_2 & & & = 14 && \tag{constraint 3} \\ & & \rlap{x_i \ge 0, i = 1, 2, 3} \end{alignat}

We treat $\max$, $z$, each variable, $\pm$ sign and RHS as one separate column, while leaving an extra empty column on the right. Then we count the number of separators &, add one into this number then divide it by two. (e.g. (9 + 1) ÷ 2 = 5)

\rlap is used so that the last row spans over one column.

Optional: \tag is used to label the constraints.

## Change MATLAB/Octave matrices to $\rm\LaTeX$ code

To get fractions, execute format rat at the beginning.

Writing manually the $\rm\LaTeX$ code for a matrix with many rows and columns in Octave is tedious. The Octave function

strcat("\\begin{bmatrix}\n",strrep(strrep(mat2str(A)," "," & "), ...
";"," \\\\\n")(2:end-1),"\n\\end{bmatrix}\n")

converts

A = [1 2 2; 2 3 4; 4 4 2]
A =

1   2   2
2   3   4
4   4   2

to

\begin{bmatrix}
1 & 2 & 2 \\
2 & 3 & 4 \\
4 & 4 & 2
\end{bmatrix}

so that pasting the generated code gives

$$\begin{bmatrix} 1 & 2 & 2 \\ 2 & 3 & 4 \\ 4 & 4 & 2 \end{bmatrix}.$$

## Simplex tableaux

Since the coefficient of the objective value variable $z$ never changes, my habit is to omit the $z$-column to save ink.

### Normal simplex tableau

\begin{array}{rrrrrr|r}
& x_1 & x_2 & s_1 & s_2 & s_3 &    \\ \hline
s_1 &   0 &   1 &   1 &   0 &   0 &  8 \\
s_2 &   1 &  -1 &   0 &   1 &   0 &  4 \\
s_3 &   1 &   1 &   0 &   0 &   1 & 12 \\ \hline
&  -1 &  -1 &   0 &   0 &   0 &  0
\end{array}

\begin{array}{rrrrrr|r} & x_1 & x_2 & s_1 & s_2 & s_3 & \\ \hline s_1 & 0 & 1 & 1 & 0 & 0 & 8 \\ s_2 & 1 & -1 & 0 & 1 & 0 & 4 \\ s_3 & 1 & 1 & 0 & 0 & 1 & 12 \\ \hline & -1 & -1 & 0 & 0 & 0 & 0 \end{array}

It can be stacked up to give an illustration of the entering of variables at different stages.

\begin{array}{rrrrrrr|rr}
& x_1 & x_2 & s_1 & s_2 & s_3 &  w &    & \text{ratio} \\ \hline
s_1 &   0 &   1 &   1 &   0 &   0 &  0 &  8 &            - \\
w & 1^* &  -1 &   0 &  -1 &   0 &  1 &  4 &            4 \\
s_3 &   1 &   1 &   0 &   0 &   1 &  0 & 12 &           12 \\ \hdashline
&   1 &  -1 &   0 &  -1 &   0 &  0 &  4 &              \\ \hline
s_1 &   0 &   1 &   1 &   0 &   0 &  0 &  8 &              \\
x_1 &   1 &  -1 &   0 &  -1 &   0 &  1 &  4 &              \\
s_3 &   0 &   2 &   0 &   2 &   1 & -1 &  8 &              \\ \hdashline
&   0 &   0 &   0 &   0 &   0 & -1 &  0 &
\end{array}

\begin{array}{rrrrrrr|rr} & x_1 & x_2 & s_1 & s_2 & s_3 & w & & \text{ratio} \\ \hline s_1 & 0 & 1 & 1 & 0 & 0 & 0 & 8 & - \\ w & 1^* & -1 & 0 & -1 & 0 & 1 & 4 & 4 \\ s_3 & 1 & 1 & 0 & 0 & 1 & 0 & 12 & 12 \\ \hdashline & 1 & -1 & 0 & -1 & 0 & 0 & 4 & \\ \hline s_1 & 0 & 1 & 1 & 0 & 0 & 0 & 8 & \\ x_1 & 1 & -1 & 0 & -1 & 0 & 1 & 4 & \\ s_3 & 0 & 2 & 0 & 2 & 1 & -1 & 8 & \\ \hdashline & 0 & 0 & 0 & 0 & 0 & -1 & 0 & \end{array}

### Dual simplex tableau

\begin{array}{rrrrrrrr|r}
& x_1 & x_2 & x_3 & x_4 & x_5 & x_6 &  x_7 &        \\ \hline
x_4 &   0 &  -3 &   7 &   1 &   0 &   0 &    2 & 2M  -4 \\
x_5 &   0 &  -9 &   0 &   0 &   1 &   0 &   -1 & -M  -3 \\
x_6 &   0 &   6 &  -1 &   0 &   0 &   1 & -4^* & -4M +8 \\
x_1 &   1 &   0 &   1 &   0 &   0 &   0 &    1 &      M \\ \hline
&   0 &   1 &   1 &   0 &   0 &   0 &    2 &     2M \\
\text{ratio} &     &     &   1 &     &     &     &  1/2 &
\end{array}

\begin{array}{rrrrrrrr|r} & x_1 & x_2 & x_3 & x_4 & x_5 & x_6 & x_7 & \\ \hline x_4 & 0 & -3 & 7 & 1 & 0 & 0 & 2 & 2M -4 \\ x_5 & 0 & -9 & 0 & 0 & 1 & 0 & -1 & -M -3 \\ x_6 & 0 & 6 & -1 & 0 & 0 & 1 & -4^* & -4M +8 \\ x_1 & 1 & 0 & 1 & 0 & 0 & 0 & 1 & M \\ \hline & 0 & 1 & 1 & 0 & 0 & 0 & 2 & 2M \\ \text{ratio} & & & 1 & & & & 1/2 & \end{array}

It can be stacked up to give a theoretical illustration of what happens in the upcoming steps.

\begin{array}{rrrrrrr|r} & x_1 & x_2 & x_3 & s_1 & s_2 & s_3 & \\ \hline s_1 & -2 & 0 & -2 & 1 & 0 & 0 & -60 \\ s_2 & -2 & -4^* & -5 & 0 & 1 & 0 & -70 \\ s_3 & 0 & -3 & -1 & 0 & 0 & 1 & -27 \\ \hdashline & 8 & 10 & 25 & 0 & 0 & 0 & 0 \\ \text{ratio} & -4 & -5/2 & -5 & & & & \\ \hline s_1 & -2^* & 0 & -2 & 1 & 0 & 0 & -60 \\ x_2 & 1/2 & 1 & 5/4 & 0 & -1/4 & 0 & 35/2 \\ s_3 & 3/2 & 0 & 11/4 & 0 & -3/4 & 1 & 51/2 \\ \hdashline & 3 & 0 & 25/2 & 0 & 5/2 & 0 & -175 \\ \text{ratio} & -3/2 & & 25/4 & & & & \\ \hline x_1 & 1 & 0 & 1 & -1/2 & 0 & 0 & 30 \\ x_2 & 0 & 1 & 3/4 & 1/4 & -1/4 & 0 & 5/2 \\ s_3 & 0 & 0 & 5/4 & 3/4 & -3/4^* & 1 & -39/2 \\ \hdashline & 0 & 0 & 19/2 & 3/2 & 5/2 & 0 & -265 \\ \text{ratio} & & & & & \dots & & \\ \hline x_1 & 1 & 0 & 1 & -1/2 & 0 & 0 & 30 \\ x_2 & 0 & 1 & 1/3 & 0 & 0 & -1/3 & 9 \\ s_2 & 0 & 0 & -5/3 & -1 & 1 & -4/3 & 26 \\ \hdashline & 0 & 0 & 41/3 & 4 & 0 & 10/3 & -330 \end{array}

## Duality

A picture is worth a thousand words.

$$\require{extpfeil} % produce extensible horizontal arrows \begin{array}{ccc} % arrange LPPs % first row % first LPP \begin{array}{ll} \max & z = c^T x \\ \text{s.t.} & A x \le b \\ & x \ge 0 \end{array} & \xtofrom{\text{duality}} & % second LPP \begin{array}{ll} \min & v = b^T y \\ \text{s.t.} & A^T y \ge c \\ & y \ge 0 \end{array} \\ ({\cal PC}) & & ({\cal DC}) \\ \text{add } {\Large \downharpoonleft} \text{slack var} & & \text{minus } {\Large \downharpoonright} \text{surplus var}\\ % Change to your favorite arrow style % % second row % third LPP \begin{array}{ll} \max & z = c^T x \\ \text{s.t.} & A x + s = b \\ & x,s \ge 0 \end{array} & \xtofrom[\text{some steps skipped}]{\text{duality}} & % fourth LPP \begin{array}{ll} \min & v = b^T y \\ \text{s.t.} & A^T y - t = c \\ & y,t \ge 0 \end{array} \\ ({\cal PS}) & & ({\cal DS}) % \end{array}$$

• It must have taken more than a thousand words to write that picture though :D – user477343 Jul 20 at 9:25

## protected by MJDMay 28 '15 at 17:18

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?