Matlab中使用LaTeX字符编辑数学公式
- 格式:pdf
- 大小:301.06 KB
- 文档页数:16
Matlab中使用LaTeX字符编辑数学公式1. Using LaTaX to format math equations引自:/cn/help/matlab/creating_plots/adding-text-annotations-to-graphs.htmlThe LaTeX markup language evolved from TeX, and has a superset of its capabilities. LaTeX gives you more elaborate control over specifying and styling mathematical symbols.Latex排版语言源自于Tex,拥有独特的魅力;它能够使你轻易的生成精美的规范格式的数学符号。
The following example illustrates some LaTeX typesetting capabilities when used with the text function. Because the default interpreter is for TeX, you need to specify the parameter-value pair 'interpreter','latex' when typesetting equations such as are contained in the following script:下面的例子用来介绍一些在文本标注中使用LaTeX排版功能,由于文本标签中的默认解释程序语言为TeX,在利用LaTeX语言编辑包含下列脚本中的一些数学方程的时候,就得需要把文本标签的参数‘interpreter’设置为‘latex’:%% LaTeX Examples--Some well known equations rendered in LaTeX%figure('color','white','units','inches','position',[2 2 4 6.5]);axis off%% A matrix(矩阵); LaTeX code is% \hbox {magic(3) is } \left( {\matrix{ 8 & 1 & 6 \cr% 3 & 5 & 7 \cr 4 & 9 & 2 } } \right)h(1) = text('units','inch', 'position',[.2 5], ...'fontsize',14, 'interpreter','latex', 'string',...['$$\hbox {magic(3) is } \left( {\matrix{ 8 & 1 & 6 \cr'...'3 & 5 & 7 \cr 4 & 9 & 2 } } \right)$$']);%% A 2-D rotation transform(坐标旋转); LaTeX code is% \left[ {\matrix{\cos(\phi) & -\sin(\phi) \cr% \sin(\phi) & \cos(\phi) \cr}}% \right] \left[ \matrix{x \cr y} \right]%% $$ \left[ {\matrix{\cos(\phi)% & -\sin(\phi) \cr \sin(\phi) & \cos(\phi) % \cr}}% \right] \left[ \matrix{x \cr y} \right] $$%h(2) = text('units','inch', 'position',[.2 4], ...'fontsize',14, 'interpreter','latex', 'string',...['$$\left[ {\matrix{\cos(\phi) & -\sin(\phi) \cr'...'\sin(\phi) & \cos(\phi) \cr}} \right]'...'\left[ \matrix{x \cr y} \right]$$']);%% The Laplace transform(拉普拉斯变换); LaTeX code is% L\{f(t)\} \equiv F(s) = \int_0^\infty\!\!{e^{-st}f(t)dt}% $$ L\{f(t)\} \equiv F(s) = \int_0^\infty\!\!{e^{-st}f(t)dt} $$% The Initial Value Theorem for the Laplace transform:% \lim_{s \rightarrow \infty} sF(s) = \lim_{t \rightarrow 0} f(t)% $$ \lim_{s \rightarrow \infty} sF(s) = \lim_{t \rightarrow 0}% f(t) $$%h(3) = text('units','inch', 'position',[.2 3], ...'fontsize',14, 'interpreter','latex', 'string',...['$$L\{f(t)\} \equiv F(s) = \int_0^\infty\!\!{e^{-st}'...'f(t)dt}$$']);%% The definition of e(e的定义); LaTeX code is% e = \sum_{k=0}^\infty {1 \over {k!} }% $$ e = \sum_{k=0}^\infty {1 \over {k!} } $$%h(4) = text('units','inch', 'position',[.2 2], ...'fontsize',14, 'interpreter','latex', 'string',...'$$e = \sum_{k=0}^\infty {1 \over {k!} } $$');%% Differential equation(微分方程)% The equation for motion of a falling body with air resistance% LaTeX code is% m \ddot y = -m g + C_D \cdot {1 \over 2} \rho {\dot y}^2 \cdot A% $$ m \ddot y = -m g + C_D \cdot {1 \over 2} \rho {\dot y}^2% \cdot A $$%h(5) = text('units','inch', 'position',[.2 1], ...'fontsize',14, 'interpreter','latex', 'string',...['$$m \ddot y = -m g + C_D \cdot {1 \over 2}'...'\rho {\dot y}^2 \cdot A$$']);%% Integral Equation(积分方程); LaTeX code is% \int_{0}^{\infty} x^2 e^{-x^2} dx = \frac{\sqrt{\pi}}{4}% $$ \int_{0}^{\infty} x^2 e^{-x^2} dx = \frac{\sqrt{\pi}}{4} $$%h(6) = text('units','inch', 'position',[.2 0], ...'fontsize',14, 'interpreter','latex', 'string',...'$$\int_{0}^{\infty} x^2 e^{-x^2} dx = \frac{\sqrt{\pi}}{4}$$');2. Latex字符在matlab中应用试验为了在图例中编辑一个分段函数的数学式子,从而接触到了Latex字符,网上找了一些资料,几经试验,在零基础上终于学习利用latex字符编出了分段函数的数学表达式,在这里分享一下学习试验过程中出现的问题和成果。
(1)array环境下显示多行数据h1=text(0.1,0.5,str1,'interpreter','latex');set(h1,'fontname','times','fontsize',16,'BackgroundColor','magenta')这里演示了一个最简单的数列,array最基本的模式是:\begin{array}{}…\End{array};其中中间大括号里面的内容是表示数列每列对齐方式,有三种对齐方式:l(left)、c(center)、r(right);在这里“\\”表示断行符。
str1=['$$\begin{array}{clcr}'...'a+b+c & uv & x-y & 27\\'...'a+b & u+v & z & 134\\'...'a & 3u+uw & xyz &2\end{array}$$'];从上例中可以看到对齐方式的应用效果;同时每列之间的几乎无间隔,从第一个字符串和第二字符串可以看出,这样效果非常不好,最好把列与列之间有一定的间隔才好,下面将要说到latex中的空格问题。