To describe a mathematical process or method used in your code, insert equations into your live script or function. Only text lines can contain equations. If you insert an equation into a code line, MATLAB® places the equation into a new text line directly under the selected code line.
There are two ways to insert an equation into a live script or function.
Insert an equation interactively — You can build an equation interactively by selecting from a graphical display of symbols and structures.
Insert a LaTeX
equation — You can enter
LaTeX
commands and the Live Editor inserts the
corresponding equation.
To insert an equation interactively:
Go to the Insert tab and click
Equation.
A blank equation appears.
Build your equation by selecting symbols, structures, and matrices
from the options displayed in the Equation tab.
View additional options by clicking the to the right of each section.
When adding or editing a matrix, a context menu appears, which you can use to delete and insert rows and columns.
Format your equation using the options available in the Format section. Formatting is only available for text within the equation. Numbers and symbols cannot be formatted. The formatting option is disabled unless the cursor is placed within text that can be formatted.
The equation editor provides a few shortcuts for adding elements to your equation:
To insert symbols, structures, and matrices, type a backslash followed
by the name of the symbol. For example, type \pi
to
insert a π symbol into the equation. To discover the name of a symbol or
structure, hover over the corresponding icon in the
Equation tab. You can also type backslash in
the equation editor to bring up a completion menu of all supported
names.
Although the
\
syntax
closely resembles name
LaTeX
command syntax,
entering full LaTeX
expressions is not
supported when inserting equations interactively.
To insert subscripts, superscripts, and fractions, use the symbols
‘_
’, ‘^
’ or
‘/
’. For example:
Type x_2
to insert into the equation.
Type x^2
to insert into the equation.
Type x/2
to insert into the equation.
To insert a new column into a matrix, type a ‘,’ at the end of the last cell in a matrix row. To insert a new row, type a semicolon ‘;’ at the end of the last cell in a matrix column.
To insert the common symbols listed in this table, type a combination of other symbols.
Keyboard Input | Symbol | Keyboard Input | Symbol | Keyboard Input | Symbol |
---|---|---|---|---|---|
| | | ∥ | => | ⇒ | != | ≠ |
|= | ⊧ | <--> | ![]() | !< | ≮ |
|– | ⊢ | <-> | !> | ≯ | |
–| | ⊣ | <= | ≤ | !<= | ≰ |
-> | → | >= | ≥ | !>= | ≱ |
<- | ← | <> | ≠ | ||
<-- | ![]() | ~= | ≠ |
LaTeX
EquationTo insert a LaTeX
equation:
Go to the Insert tab, click
Equation and select LaTeX
Equation.
Enter a LaTeX
expression in the dialog box that
appears. For example, you can enter \sin(x) =
\sum_{n=0}^{\infty}{\frac{(-1)^n
x^{2n+1}}{(2n+1)!}}
.
The preview pane shows a preview of equation as it would appear in the live script.
Press OK to insert the equation into your live script.
LaTeX
expressions describe a wide range of equations. This
table shows several examples of LaTeX
expressions and their
appearance when inserted into a live script.
LaTeX Expression | Equation in Live Script |
---|---|
a^2 + b^2 = c^2 | |
\int_{0}^{2} x^2\sin(x) dx | |
\sin(x) = \sum_{n=0}^{\infty}{\frac{(-1)^n
x^{2n+1}}{(2n+1)!}} | |
{a,b,c} \neq \{a,b,c\} | |
x^{2} \geq 0\qquad \text{for
all}x\in\mathbf{R} | |
\matrix{a & b \cr c & d} |
LaTeX
CommandsMATLAB supports most standard LaTeX
math mode
commands. These tables show a list of supported LaTeX
commands.
Greek/Hebrew Letters
Symbol | LaTeX Command | Symbol | LaTeX Command | Symbol | LaTeX Command |
---|---|---|---|---|---|
α | alpha | ν | nu | ξ | xi |
β | beta | ω | omega
| ζ | zeta |
χ | chi | о | omicron | ɛ | varepsilon |
δ | delta | ϕ | phi | φ | varphi |
ε | epsilon | π | pi
| ϖ | varpi |
η | eta | ψ | psi | ϱ | varrho |
v | gamma
| ρ | rho | ς | varsigma |
ι | iota | σ | sigma
| vartheta | |
κ | kappa | τ | tau | א | aleph |
λ | lambda
| θ | theta
| ||
μ | mu | υ | upsilon | ||
Δ | Delta
| Φ | Phi | Θ | Theta
|
Γ | Gamma | Π | Pi
| ϒ | Upsilon |
Λ | Lambda
| Ψ | Psi | Ξ | Xi |
Ω | Omega
| Σ | Sigma
|
Operator Symbols
Symbol | LaTeX Command | Symbol | LaTeX Command | Symbol | LaTeX Command |
---|---|---|---|---|---|
* | ast | ± | pm | ∩ | cap
|
☆ | star | ∓ | mp | ∪ | cup
|
cdot | ∐ | amalg | ⊎ | uplus | |
○ | circ | ⊙ | odot
| ⊓ | sqcap
|
• | bullet | ⊖ | ominus
| ⊔ | sqcup
|
⋄ | diamond | ⊕ | oplus
| ∧ | wedge , land |
∖ | setminus | ⊘ | oslash
| ∨ | vee , lor |
× | times | ⊗ | otimes | ◁ | triangleleft |
÷ | div | † | dagger | ▷ | triangleright |
⊥ | bot , perp | ‡ | ddagger | bigtriangleup | |
⊤ | top | ≀ | wr | bigtriangledown | |
∑ | sum | ∏ | prod | ∫ | int , intop |
biguplus | bigoplus | bigvee | |||
bigcap | bigotimes | bigwedge | |||
bigcup | bigodot | bigsqcup |
Relation Symbols
Symbol | LaTeX Command | Symbol | LaTeX Command | Symbol | LaTeX Command |
---|---|---|---|---|---|
≡ | equiv
| < | lt | > | gt |
≅ | cong | ≤ | le , leq
| ≥ | ge , geq |
≠ | neq , ne ,
not= | ≮ | not< | ≯ | not> |
∼ | sim | ≺ | prec | ≻ | succ |
≃ | simeq | ≼ | preceq | ≽ | succeq |
≈ | approx | ≪ | ll | ≫ | gg |
≍ | asymp | ⊂ | subset | ⊃ | supset |
≐ | doteq | ⊆ | subseteq | ⊇ | supseteq |
∝ | propto | ⊑ | sqsubseteq | ⊒ | sqsupseteq |
⊧ | models | ∣ | mid | ∊ | in |
⋈ | bowtie | ∥ | parallel | ∉ | notin |
⊢ | vdash | ⇔ | iff | ∍ | ni , owns |
⊣ | dashv |
The leq
, geq
,
equiv
, approx
,
cong
, sim
,
simeq
, models
,
ni
, succ
,
succeq
, prec
,
preceq
, parallel
,
subset
, supset
,
subseteq
, and supseteq
commands can be combined with the not
command to
create the negated version of the symbol. For example,
\not\leq
creates the symbol ≰.
Arrows
Symbol | LaTeX Command | Symbol | LaTeX Command | Symbol | LaTeX Command |
---|---|---|---|---|---|
← | leftarrow | → | rightarrow | ↑ | uparrow |
⇐ | Leftarrow | ⇒ | Rightarrow | ⇑ | Uparrow |
![]() | longleftarrow | ![]() | longrightarrow | ↓ | downarrow |
![]() | Longleftarrow | ![]() | Longrightarrow | ⇓ | Downarrow |
↩ | hookleftarrow | ↪ | hookrightarrow | updownarrow | |
↽ | leftharpoondown | ⇁ | rightharpoondown | Updownarrow | |
↼ | leftharpoonup | ⇀ | rightharpoonup | leftrightarrow | |
↙ | swarrow | ↗ | nearrow | Leftrightarrow | |
↖ | nwarrow | ↘ | searrow | ![]() | longleftrightarrow |
↦ | mapsto | ![]() | longmapsto | ![]() | Longleftrightarrow |
Brackets
Symbol | LaTeX
Command | Symbol | LaTeX
Command | Symbol | LaTeX
Command |
---|---|---|---|---|---|
{ | lbrace | } | rbrace | | | vert |
[ | lbrack | ] | rbrack | ‖ | Vert |
〈 | langle | 〉 | rangle | \ | backslash |
⌈ | lceil | ⌉ | rceil | ||
⌊ | lfloor | ⌋ | rfloor |
Sample | LaTeX Command | Sample | LaTeX Command | ||
---|---|---|---|---|---|
![]() | big , bigl ,
bigr , bigm | brace | |||
![]() | Big , Bigl ,
Bigr , Bigm | brack | |||
![]() | bigg , biggl ,
biggr ,
biggm | choose | |||
![]() | Bigg , Biggl ,
Biggr ,
Biggm |
Misc Symbols
Symbol | LaTeX Command | Symbol | LaTeX Command | Symbol | LaTeX Command |
---|---|---|---|---|---|
∞ | infty
| ∀ | forall | ℘ | wp |
∇ | nabla | ∃ | exists | ∠ | angle |
∂ | partial | emptyset | △ | triangle | |
ℑ | Im | ![]() | i | ħ | hbar |
ℜ | Re | ![]() | j | ′ | prime |
ℓ | ell | ![]() | imath | ¬ | lnot , neg |
… | dots , ldots | ![]() | jmath | surd | |
cdots | : | colon | ← | gets | |
ddots | cdotp | → | to | ||
⋮ | vdots | ldotp |
The exists
command can be combined with the
not
command to create the negated version of the
symbol. For example, \not\exists
creates the symbol
∄.
Accents
Symbol | LaTeX Command | Symbol | LaTeX Command | Symbol | LaTeX Command |
---|---|---|---|---|---|
á | acute | ddot | tilde | ||
bar | dot | vec | |||
breve | à | grave | |||
check | hat |
Functions
Sample | LaTeX
Command | Sample | LaTeX
Command | Sample | LaTeX
Command |
---|---|---|---|---|---|
arccos | det | ln | |||
arcsin | dim | log | |||
arctan | exp | max | |||
arg | gcd | min | |||
cos | hom | Pr | |||
cosh | ker | sec | |||
cot | lg | sin | |||
coth | lim | sinh | |||
csc | liminf | sup | |||
deg | limsup | tan |
Math Constructs
Sample | LaTeX Command | Sample | LaTeX Command | Sample | LaTeX Command |
---|---|---|---|---|---|
frac | over | stackrel ,
overset | |||
sqrt | overwithdelims | underset | |||
bmod | overleftarrow | pmatrix | |||
pmod | overrightarrow | matrix | |||
widehat | overleftrightarrow | begin{array} | |||
widetilde | limits | begin{cases} | |||
left | right | hline |
To create a matrix using the matrix
and
pmatrix
commands, use the
&
symbol to separate columns, and
\cr
to separate rows. For example, to create a
2–by–2 matrix, use the expression \matrix{a & b \cr c &
d}
.
White Space
Sample | LaTeX
Command | Sample | LaTeX
Command | Sample | LaTeX
Command |
---|---|---|---|---|---|
![]() | negthinspace | mathord | mathopen | ||
thinspace | mathop | mathclose | |||
enspace | mathbin | mathinner | |||
quad | mathrel | kern ,
mkern | |||
qquad | mathpunct |
Text Styling
Sample | LaTeX Command | Sample | LaTeX Command | Sample | LaTeX Command |
---|---|---|---|---|---|
| displaystyle | text ,
textnormal | texttt | ||
| textstyle | bf , textbf ,
mathbf | textsf | ||
| scriptstyle | it , textit ,
mathit | cal ,
mathcal | ||
| scriptscriptstyle | rm , textrm ,
mathrm | hbox , mbox |