Table of Contents
1 将Matlab中公式转化为LaTeX公式
1.1 已知公式的转换
'$$\int_0^x\!\int_y dF(u,v)$$'
1.2 未知公式的转换
latex(taylor(sin(t), 16))
运行结果为:
>> latex(taylor(sin(t),16))
ans =
- \frac{t^{15}}{1307674368000} + \frac{t^{13}}{6227020800} - \frac{t^{11}}{39916800} + \frac{t^9}{362880} - \frac{t^7}{5040} + \frac{t^5}{120} - \frac{t^3}{6} + t
结果为字符串类型。
2 将Matlab运行结果的公式显示为适合阅读形式
在命令行界面下不是能显示出来适合阅读的公式的,要想显示必须要图形界面下:
text('Interpreter','latex',...
'String','$$\int_0^x\!\int_y dF(u,v)$$',...
'position',[.5 .5],...
'fontsize',16)
text(.1,.5,['\fontsize{16}black {\color{magenta}magenta '...
'\color[rgb]{0 .5 .5}teal \color{red}red} black again'])
text(0.05,0.2,['$$',latex(taylor(sin(t), 16)),'$$'],'interpreter','latex','fontsize',12);
2.1 text函数各个属性
- fontsize 字体大小
- positin 后跟坐标位置
- string 后跟要显示的latex字符串
- 几乎所有的latex命令在此都可在此使用,包括字体大小\fontsize,颜色\color,字体\ …
fontname,各种字体属性:黑体\bf 斜体\it 罗马字体\rm等
- 几乎所有的latex命令在此都可在此使用,包括字体大小\fontsize,颜色\color,字体\ …
- interpreter 后跟编译选项,此处用latex或者tex
3 在线转换网址
如果本机安装latex编译器(CTeX或者Texlive)可以本地编译生成公式,也可以利用在线latex公式编译网站来编译:codecogs …
选择Equation Editor ->Integrated …
Editor,然后把刚才生成的latex字符串粘贴到公式框中,会自动在输入框下面动态生成相应地公式,然后单击下面的Download Image即可保存到本地。
也可以在生成公式上右击复制图片链接地址,之后便可以在自己的博客中或论坛上复制该地址,便可显示相应地公式。
例如上面的:
- \frac{t^{15}}{1307674368000} + \frac{t^{13}}{6227020800} - \frac{t^{11}}{39916800} + \frac{t^9}{362880} - \frac{t^7}{5040} + \frac{t^5}{120} - \frac{t^3}{6} + t
生成如下公式:
4 实践
Example ― Using LaTeX to Format Math Equations
The 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.
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 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; 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}$$');
Date: 2012-05-17 22:13:32
HTML generated by org-mode 6.33x in emacs 23