利用MATLAB编程绘图时,有时需要在标题、坐标轴中添加数学公式、希腊字母等特殊字符,此时利用LaTex语句即可完美插入相关内容,现将部分LaTex语法以及常用特殊符号汇总如下:
一、对MATLAB生成的图形标注MATLAB图形中title、xlabel、ylabel、zlable、textbox、legend等的Interpreter属性包括latex、tex和none,其中默认为tex。需要使用LaTex时,将Interpreter属性设置为latex。在MATLAB中使用LaTex的格式有三种:
1、( Latex Command )2、$ LaTex Command $3、$$ LaTex Command $$案例:
x = 0:0.1:2*pi;y1 = sin(x);y2 = cos(x)*0.5;plot(x,y1,x,y2);legend({'y = sin(x)','$$ y = frac{cos(x)}{2}$$'},'interpreter','latex');set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置二、具体公式编辑 2.1 字符位置设置 序号需求函数字符结构示例1上角标^{ }title( '$ a^2 + b^2 = c^2 $ ', 'interpreter', 'latex')2下角标_{ }title( '$ a_2 + b_2 = c_{bd} $', 'interpreter', 'latex' )2.2 字符字体设置
1、字体加粗:bf{ x }
2、字体倾斜1:it{ x }
3、字体倾斜2:sl{ x }
4、正常字体:rm{ x }
5、设置字体名:fontname{ 字体名 }
6、设置字体大小:fontsize{ 字体大小 }
7、设置字体颜色:color{ red }
可用颜色包括:red、green、yellow、magenta、blue、black、white、cyan、gray、barkGreen、orange、lightblue。
% Demox = -5:0.05:5;y = x.^3 + 1;plot(x,y);grid on;title('$y = x^2 + a_0 + bf{A_1} + it{A_2} + sl{A_3}$','interpreter','latex');set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置 2.3 具体公式编辑1、求和运算:sum_{ i=1 }^{ n }
2、积分运算:int_{ x_1 }^{ x_2 }
3、极限运算:
$$lim_{n rightarrow infty}$$ % n趋于无穷符号在lim正下方$lim_{n rightarrow infty}$ % n趋于无穷符号在lim右下角% 区别是符号在正下方左右各用了2个$符号,符号在右下角左右各用了1个$符号4、分式运算:frac{ x^2 + y^2 } { x+y+z }
% Demox = -5:0.05:5;y1 = x.^3 + 1;y2 = x.^3 ;plot(x,y1,x,y2);grid on;title('$ y = sum_{i=1}^{n}x_{i} + frac{1}{2} + int_{0}^{5}x$','interpreter','latex');legend({'$$lim_{n rightarrow infty}$$','$ lim_{n rightarrow infty} $'},'interpreter','latex')set(gcf,'unit','centimeters','Position',[4 2 12 5.5]);% 设置图片大小与位置5、根式运算:sqrt{ x^2 + y^2 }
6、上划线:overline{ x }
7、下划线:underline{ x }
8、卧式花括号:overbrace{ x+y+z }
% Demox = -5:0.05:5;y = x.^3 + 1;plot(x,y);grid on;title('$y = x^2 + overline{x} + underline{x} + sqrt{x} + overbrace{x+y}$','interpreter','latex');set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置9、仰视花括号:underbrace{ a+b+c }
10、戴帽命令:hat{ x }、check{ x }、breve{ x }、widehat{ A+B }、widetilde{ a+b }、vec{ x }、vec{ imath }
11、堆砌命令:stackrel{ rm def }{ = } f(x)
12、省略号:cdots、ldots、vdots、ddots
% Demox = -5:0.05:5;y = x.^3 + 1;plot(x,y);grid on;title('$underbrace{x+y} + hat{x} + check{x} + breve{x} + vec{imath} + y stackrel{rm def}{=} + cdots + ldots +vdots +ddots$ ','interpreter','latex');set(gcf,'unit','centimeters','Position',[4 2 12 5.5]); % 设置图片大小与位置 三、特殊符号汇总 表1 特殊符号 序号函数字符表征符号函数字符表征符号函数字符表征符号1alpha
α
upsilon
υ
sim
~
2angle
∠
phi
Φ
leq
≤
3ast
*
chi
χ
infty
∞
4beta
β
psi
ψ
clubsuit
♣
5gamma
γ
omega
ω
diamondsuit
♦
6delta
δ
Gamma
Γ
heartsuit
♥
7epsilon
ɛ
Delta
Δ
spadesuit
♠
9zeta
ζ
Theta
Θ
leftrightarrow
↔
10eta
η
Lambda
Λ
leftarrow
←
11theta
Θ
Xi
Ξ
Leftarrow
⇐
12vartheta
ϑ
Pi
Π
uparrow
↑
13iota
ι
Sigma
Σ
rightarrow
→
14kappa
κ
Upsilon
ϒ
Rightarrow
⇒
15lambda
λ
Phi
Φ
downarrow
↓
16mu
µ
Psi
Ψ
circ
º
17nu
ν
Omega
Ω
pm
±
18xi
ξ
forall
∀
geq
≥
19pi
π
exists
∃
propto
∝
20rho
ρ
ni
∍
partial
∂
21sigma
σ
cong
≅
bullet
•
22varsigma
ς
approx
≈
div
÷
23tau
τ
Re
ℜ
neq
≠
24equiv
≡
oplus
⊕
aleph
ℵ
25Im
ℑ
cup
∪
wp
℘
26otimes
⊗
subseteq
⊆
oslash
∅
27cap
∩
in
∈
supseteq
⊇
28supset
⊃
lceil
⌈
subset
⊂
29int
∫
cdot
·
o
ο
30rfloor
⌋
neg
¬
nabla
∇
31lfloor
⌊
times
x
ldots
...
32perp
⊥
surd
√
prime
´
33wedge
∧
varpi
ϖ