Show More
@@ -0,0 +1,347 b'' | |||||
|
1 | { | |||
|
2 | "metadata": { | |||
|
3 | "name": "Typesetting Math Using MathJax" | |||
|
4 | }, | |||
|
5 | "nbformat": 3, | |||
|
6 | "nbformat_minor": 0, | |||
|
7 | "worksheets": [ | |||
|
8 | { | |||
|
9 | "cells": [ | |||
|
10 | { | |||
|
11 | "cell_type": "markdown", | |||
|
12 | "metadata": {}, | |||
|
13 | "source": [ | |||
|
14 | "The Markdown parser included in IPython is MathJax-aware. This means that you can freely mix in mathematical expressions using the [MathJax subset of Tex and LaTeX](http://docs.mathjax.org/en/latest/tex.html#tex-support). [Some examples from the MathJax site](http://www.mathjax.org/demos/tex-samples/) are reproduced below, as well as the Markdown+TeX source." | |||
|
15 | ] | |||
|
16 | }, | |||
|
17 | { | |||
|
18 | "cell_type": "markdown", | |||
|
19 | "metadata": {}, | |||
|
20 | "source": [ | |||
|
21 | "# Motivating Examples\n", | |||
|
22 | "\n", | |||
|
23 | "---\n", | |||
|
24 | "\n", | |||
|
25 | "## The Lorenz Equations\n", | |||
|
26 | "### Source\n", | |||
|
27 | "```\\begin{aligned}\n", | |||
|
28 | "\\dot{x} & = \\sigma(y-x) \\\\\n", | |||
|
29 | "\\dot{y} & = \\rho x - y - xz \\\\\n", | |||
|
30 | "\\dot{z} & = -\\beta z + xy\n", | |||
|
31 | "\\end{aligned}\n", | |||
|
32 | "```\n", | |||
|
33 | "### Display\n", | |||
|
34 | "\\begin{aligned}\n", | |||
|
35 | "\\dot{x} & = \\sigma(y-x) \\\\\n", | |||
|
36 | "\\dot{y} & = \\rho x - y - xz \\\\\n", | |||
|
37 | "\\dot{z} & = -\\beta z + xy\n", | |||
|
38 | "\\end{aligned}" | |||
|
39 | ] | |||
|
40 | }, | |||
|
41 | { | |||
|
42 | "cell_type": "markdown", | |||
|
43 | "metadata": {}, | |||
|
44 | "source": [ | |||
|
45 | "## The Cauchy-Schwarz Inequality\n", | |||
|
46 | "### Source\n", | |||
|
47 | "```\\begin{equation*}\n", | |||
|
48 | "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n", | |||
|
49 | "\\end{equation*}\n", | |||
|
50 | "```\n", | |||
|
51 | "### Display\n", | |||
|
52 | "\\begin{equation*}\n", | |||
|
53 | "\\left( \\sum_{k=1}^n a_k b_k \\right)^2 \\leq \\left( \\sum_{k=1}^n a_k^2 \\right) \\left( \\sum_{k=1}^n b_k^2 \\right)\n", | |||
|
54 | "\\end{equation*}" | |||
|
55 | ] | |||
|
56 | }, | |||
|
57 | { | |||
|
58 | "cell_type": "markdown", | |||
|
59 | "metadata": {}, | |||
|
60 | "source": [ | |||
|
61 | "## A Cross Product Formula\n", | |||
|
62 | "### Source\n", | |||
|
63 | "```\\begin{equation*}\n", | |||
|
64 | "\\mathbf{V}_1 \\times \\mathbf{V}_2 = \\begin{vmatrix}\n", | |||
|
65 | "\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\n", | |||
|
66 | "\\frac{\\partial X}{\\partial u} & \\frac{\\partial Y}{\\partial u} & 0 \\\\\n", | |||
|
67 | "\\frac{\\partial X}{\\partial v} & \\frac{\\partial Y}{\\partial v} & 0\n", | |||
|
68 | "\\end{vmatrix} \n", | |||
|
69 | "\\end{equation*}\n", | |||
|
70 | "```\n", | |||
|
71 | "### Display\n", | |||
|
72 | "\\begin{equation*}\n", | |||
|
73 | "\\mathbf{V}_1 \\times \\mathbf{V}_2 = \\begin{vmatrix}\n", | |||
|
74 | "\\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\\n", | |||
|
75 | "\\frac{\\partial X}{\\partial u} & \\frac{\\partial Y}{\\partial u} & 0 \\\\\n", | |||
|
76 | "\\frac{\\partial X}{\\partial v} & \\frac{\\partial Y}{\\partial v} & 0\n", | |||
|
77 | "\\end{vmatrix} \n", | |||
|
78 | "\\end{equation*}" | |||
|
79 | ] | |||
|
80 | }, | |||
|
81 | { | |||
|
82 | "cell_type": "markdown", | |||
|
83 | "metadata": {}, | |||
|
84 | "source": [ | |||
|
85 | "## The probability of getting \\(k\\) heads when flipping \\(n\\) coins is\n", | |||
|
86 | "### Source\n", | |||
|
87 | "```\\begin{equation*}\n", | |||
|
88 | "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n", | |||
|
89 | "\\end{equation*}\n", | |||
|
90 | "```\n", | |||
|
91 | "### Display\n", | |||
|
92 | "\\begin{equation*}\n", | |||
|
93 | "P(E) = {n \\choose k} p^k (1-p)^{ n-k} \n", | |||
|
94 | "\\end{equation*}" | |||
|
95 | ] | |||
|
96 | }, | |||
|
97 | { | |||
|
98 | "cell_type": "markdown", | |||
|
99 | "metadata": {}, | |||
|
100 | "source": [ | |||
|
101 | "## An Identity of Ramanujan\n", | |||
|
102 | "### Source\n", | |||
|
103 | "```\\begin{equation*}\n", | |||
|
104 | "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} =\n", | |||
|
105 | "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}\n", | |||
|
106 | "{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } } \n", | |||
|
107 | "\\end{equation*}\n", | |||
|
108 | "```\n", | |||
|
109 | "### Display\n", | |||
|
110 | "\\begin{equation*}\n", | |||
|
111 | "\\frac{1}{\\Bigl(\\sqrt{\\phi \\sqrt{5}}-\\phi\\Bigr) e^{\\frac25 \\pi}} =\n", | |||
|
112 | "1+\\frac{e^{-2\\pi}} {1+\\frac{e^{-4\\pi}} {1+\\frac{e^{-6\\pi}}\n", | |||
|
113 | "{1+\\frac{e^{-8\\pi}} {1+\\ldots} } } } \n", | |||
|
114 | "\\end{equation*}" | |||
|
115 | ] | |||
|
116 | }, | |||
|
117 | { | |||
|
118 | "cell_type": "markdown", | |||
|
119 | "metadata": {}, | |||
|
120 | "source": [ | |||
|
121 | "## A Rogers-Ramanujan Identity\n", | |||
|
122 | "### Source\n", | |||
|
123 | "```\\begin{equation*}\n", | |||
|
124 | "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots =\n", | |||
|
125 | "\\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n", | |||
|
126 | "\\quad\\quad \\text{for $|q|<1$}. \n", | |||
|
127 | "\\end{equation*}\n", | |||
|
128 | "```\n", | |||
|
129 | "### Display\n", | |||
|
130 | "\\begin{equation*}\n", | |||
|
131 | "1 + \\frac{q^2}{(1-q)}+\\frac{q^6}{(1-q)(1-q^2)}+\\cdots =\n", | |||
|
132 | "\\prod_{j=0}^{\\infty}\\frac{1}{(1-q^{5j+2})(1-q^{5j+3})},\n", | |||
|
133 | "\\quad\\quad \\text{for $|q|<1$}. \n", | |||
|
134 | "\\end{equation*}" | |||
|
135 | ] | |||
|
136 | }, | |||
|
137 | { | |||
|
138 | "cell_type": "markdown", | |||
|
139 | "metadata": {}, | |||
|
140 | "source": [ | |||
|
141 | "## Maxwell's Equations\n", | |||
|
142 | "### Source\n", | |||
|
143 | "```\\begin{aligned}\n", | |||
|
144 | "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n", | |||
|
145 | "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n", | |||
|
146 | "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n", | |||
|
147 | "\\end{aligned}\n", | |||
|
148 | "```\n", | |||
|
149 | "### Display\n", | |||
|
150 | "\\begin{aligned}\n", | |||
|
151 | "\\nabla \\times \\vec{\\mathbf{B}} -\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{E}}}{\\partial t} & = \\frac{4\\pi}{c}\\vec{\\mathbf{j}} \\\\ \\nabla \\cdot \\vec{\\mathbf{E}} & = 4 \\pi \\rho \\\\\n", | |||
|
152 | "\\nabla \\times \\vec{\\mathbf{E}}\\, +\\, \\frac1c\\, \\frac{\\partial\\vec{\\mathbf{B}}}{\\partial t} & = \\vec{\\mathbf{0}} \\\\\n", | |||
|
153 | "\\nabla \\cdot \\vec{\\mathbf{B}} & = 0 \n", | |||
|
154 | "\\end{aligned}" | |||
|
155 | ] | |||
|
156 | }, | |||
|
157 | { | |||
|
158 | "cell_type": "markdown", | |||
|
159 | "metadata": {}, | |||
|
160 | "source": [ | |||
|
161 | "# Equation Numbering and References\n", | |||
|
162 | "\n", | |||
|
163 | "---\n", | |||
|
164 | "\n", | |||
|
165 | "These equation reference examples are adapted from an [example page in the MathJax documentation](http://cdn.mathjax.org/mathjax/latest/test/sample-eqrefs.html). Note that it's okay to reference equations across cells. Click inside this cell to see the source.\n", | |||
|
166 | "\n", | |||
|
167 | "## Labeled equations and references\n", | |||
|
168 | "\n", | |||
|
169 | "Here is a labeled equation:\n", | |||
|
170 | "\\begin{equation}\n", | |||
|
171 | "x+1\\over\\sqrt{1-x^2}\\label{ref1}\n", | |||
|
172 | "\\end{equation}\n", | |||
|
173 | "\n", | |||
|
174 | "with a reference to ref1: \\ref{ref1},\n", | |||
|
175 | "and another numbered one with no label:\n", | |||
|
176 | "\\begin{equation}\n", | |||
|
177 | "x+1\\over\\sqrt{1-x^2}\n", | |||
|
178 | "\\end{equation}" | |||
|
179 | ] | |||
|
180 | }, | |||
|
181 | { | |||
|
182 | "cell_type": "markdown", | |||
|
183 | "metadata": {}, | |||
|
184 | "source": [ | |||
|
185 | "## \\nonumber and equation*\n", | |||
|
186 | "\n", | |||
|
187 | "This one uses \\nonumber:\n", | |||
|
188 | "\\begin{equation}\n", | |||
|
189 | "x+1\\over\\sqrt{1-x^2}\\nonumber\n", | |||
|
190 | "\\end{equation}\n", | |||
|
191 | "\n", | |||
|
192 | "Here's one with the equation* environment:\n", | |||
|
193 | "\\begin{equation*}\n", | |||
|
194 | "x+1\\over\\sqrt{1-x^2}\n", | |||
|
195 | "\\end{equation*}" | |||
|
196 | ] | |||
|
197 | }, | |||
|
198 | { | |||
|
199 | "cell_type": "markdown", | |||
|
200 | "metadata": {}, | |||
|
201 | "source": [ | |||
|
202 | "## Forward references\n", | |||
|
203 | "\n", | |||
|
204 | "This is a forward reference [\\ref{ref2}] and another \\eqref{ref2} for the \n", | |||
|
205 | "following equation:\n", | |||
|
206 | "\n", | |||
|
207 | "\\begin{equation}\n", | |||
|
208 | "x+1\\over\\sqrt{1-x^2}\\label{ref2}\n", | |||
|
209 | "\\end{equation}\n", | |||
|
210 | "\n", | |||
|
211 | "More math:\n", | |||
|
212 | "\\begin{equation}\n", | |||
|
213 | "x+1\\over\\sqrt{1-x^2}\n", | |||
|
214 | "\\end{equation}" | |||
|
215 | ] | |||
|
216 | }, | |||
|
217 | { | |||
|
218 | "cell_type": "markdown", | |||
|
219 | "metadata": {}, | |||
|
220 | "source": [ | |||
|
221 | "### References inline and in environments\n", | |||
|
222 | "\n", | |||
|
223 | "Here is a ref inside math: $\\ref{ref2}+1$ and text after it.\n", | |||
|
224 | "\n", | |||
|
225 | "\\begin{align} \n", | |||
|
226 | "x& = y_1-y_2+y_3-y_5+y_8-\\dots \n", | |||
|
227 | "&& \\text{by \\eqref{ref1}}\\\\ \n", | |||
|
228 | "& = y'\\circ y^* && \\text{(by \\eqref{ref3})}\\\\ \n", | |||
|
229 | "& = y(0) y' && \\text {by Axiom 1.} \n", | |||
|
230 | "\\end{align} \n", | |||
|
231 | "\n", | |||
|
232 | "### Missing references\n", | |||
|
233 | "Here's a bad ref [\\ref{ref4}] to a nonexistent label.\n", | |||
|
234 | "\n", | |||
|
235 | "### Numbering align environments\n", | |||
|
236 | "An alignment:\n", | |||
|
237 | "\\begin{align}\n", | |||
|
238 | "a&=b\\label{ref3}\\cr\n", | |||
|
239 | "&=c+d\n", | |||
|
240 | "\\end{align}\n", | |||
|
241 | "and a starred one:\n", | |||
|
242 | "\\begin{align*}\n", | |||
|
243 | "a&=b\\cr\n", | |||
|
244 | "&=c+d\n", | |||
|
245 | "\\end{align*}" | |||
|
246 | ] | |||
|
247 | }, | |||
|
248 | { | |||
|
249 | "cell_type": "markdown", | |||
|
250 | "metadata": {}, | |||
|
251 | "source": [ | |||
|
252 | "# Inline Typesetting (Mixing Markdown and TeX)\n", | |||
|
253 | "\n", | |||
|
254 | "---\n", | |||
|
255 | "\n", | |||
|
256 | "While display equations look good for a page of samples, the ability to mix math and *formatted* **text** in a paragraph is also important.\n", | |||
|
257 | "\n", | |||
|
258 | "## Source\n", | |||
|
259 | "``` This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. \n", | |||
|
260 | "```\n", | |||
|
261 | "## Display\n", | |||
|
262 | "This expression $\\sqrt{3x-1}+(1+x)^2$ is an example of a TeX inline equation in a **[Markdown-formatted](http://daringfireball.net/projects/markdown/)** sentence. " | |||
|
263 | ] | |||
|
264 | }, | |||
|
265 | { | |||
|
266 | "cell_type": "markdown", | |||
|
267 | "metadata": {}, | |||
|
268 | "source": [ | |||
|
269 | "# Other Syntax\n", | |||
|
270 | "\n", | |||
|
271 | "---\n", | |||
|
272 | "\n", | |||
|
273 | "You will notice in other places on the web that `$$` are needed explicitly to begin and end MathJax typesetting. This is **not** required if you will be using TeX environments, but the IPython notebook will accept this syntax on legacy notebooks. \n", | |||
|
274 | "\n", | |||
|
275 | "### Source\n", | |||
|
276 | "```$$\n", | |||
|
277 | "\\begin{array}{c}\n", | |||
|
278 | "y_1 \\\\\\\n", | |||
|
279 | "y_2 \\mathtt{t}_i \\\\\\\n", | |||
|
280 | "z_{3,4}\n", | |||
|
281 | "\\end{array}\n", | |||
|
282 | "$$\n", | |||
|
283 | "```\n", | |||
|
284 | "\n", | |||
|
285 | "```\n", | |||
|
286 | "$$\n", | |||
|
287 | "\\begin{array}{c}\n", | |||
|
288 | "y_1 \\cr\n", | |||
|
289 | "y_2 \\mathtt{t}_i \\cr\n", | |||
|
290 | "y_{3}\n", | |||
|
291 | "\\end{array}\n", | |||
|
292 | "$$\n", | |||
|
293 | "```\n", | |||
|
294 | "\n", | |||
|
295 | "```\n", | |||
|
296 | "$$\\begin{eqnarray} \n", | |||
|
297 | "x' &=& &x \\sin\\phi &+& z \\cos\\phi \\\\\n", | |||
|
298 | "z' &=& - &x \\cos\\phi &+& z \\sin\\phi \\\\\n", | |||
|
299 | "\\end{eqnarray}$$\n", | |||
|
300 | "```\n", | |||
|
301 | "\n", | |||
|
302 | "```\n", | |||
|
303 | "$$\n", | |||
|
304 | "x=4\n", | |||
|
305 | "$$\n", | |||
|
306 | "```\n", | |||
|
307 | "\n", | |||
|
308 | "### Display\n", | |||
|
309 | "$$\n", | |||
|
310 | "\\begin{array}{c}\n", | |||
|
311 | "y_1 \\\\\\\n", | |||
|
312 | "y_2 \\mathtt{t}_i \\\\\\\n", | |||
|
313 | "z_{3,4}\n", | |||
|
314 | "\\end{array}\n", | |||
|
315 | "$$\n", | |||
|
316 | "\n", | |||
|
317 | "$$\n", | |||
|
318 | "\\begin{array}{c}\n", | |||
|
319 | "y_1 \\cr\n", | |||
|
320 | "y_2 \\mathtt{t}_i \\cr\n", | |||
|
321 | "y_{3}\n", | |||
|
322 | "\\end{array}\n", | |||
|
323 | "$$\n", | |||
|
324 | "\n", | |||
|
325 | "$$\\begin{eqnarray} \n", | |||
|
326 | "x' &=& &x \\sin\\phi &+& z \\cos\\phi \\\\\n", | |||
|
327 | "z' &=& - &x \\cos\\phi &+& z \\sin\\phi \\\\\n", | |||
|
328 | "\\end{eqnarray}$$\n", | |||
|
329 | "\n", | |||
|
330 | "$$\n", | |||
|
331 | "x=4\n", | |||
|
332 | "$$" | |||
|
333 | ] | |||
|
334 | }, | |||
|
335 | { | |||
|
336 | "cell_type": "code", | |||
|
337 | "collapsed": false, | |||
|
338 | "input": [], | |||
|
339 | "language": "python", | |||
|
340 | "metadata": {}, | |||
|
341 | "outputs": [] | |||
|
342 | } | |||
|
343 | ], | |||
|
344 | "metadata": {} | |||
|
345 | } | |||
|
346 | ] | |||
|
347 | } No newline at end of file |
General Comments 0
You need to be logged in to leave comments.
Login now