matlab的输出符号变量的latex公式

在使用符号变量时,matlab的结果有可能非常长,并且出现*^希腊字母的英文等符号,不便于直接观察想要研究的式子,在此提供两种直接观察matlab的公式的方法

1.使用函数

function h=symdisp(s)
%//SYMDISP Display a symbolic expression in human readable form.
%// symdisplay(S) displays the symbolic expression S in a small figure window,
%// using standard mathematical notation.
%// 
%// Examples:
%//   syms x t positive
%//   f=taylor(cos(x));
%//   symdisp(f)
%//   f=int(exp(-t)*t^(x-1),t,0,inf);
%//   symdisp(f)
%//
%// Required toolbox: Symbolic Math
%//
%// See also SYMBOLIC PRETTY.
if ~isa(s,'sym')
    s=sym(s);
    %error('输入参数必须是sym类型,请使用 sym() 将你的结果转化为sym类型.')
end
S=['$',latex(s),'$'];
S=strrep(S,'&','& \quad');
S=strrep(S,'{\it','\mathrm{');
h=msgbox(S,'字符的数学展示形式');
h1=get(h,'children');
h2=h1(1);
h3=get(h2,'children');
if isempty(h3)
    h2=h1(2); h3=get(h2,'children');
end
set(h3,'visible','off')
set(h3,'interpreter','latex')
set(h3,'string',S)
set(h3,'fontsize',20)
w=get(h3,'extent');
W=get(h,'position');
W(3)=max(w(3)+10,125);
W(4)=w(4)+40;
set(h,'position',W)
h4=h1(2);
if ~strcmp(get(h4,'tag'),'OKButton'), h4=h1(1); end
o=get(h4,'position');
o(1)=(W(3)-o(3))/2;
set(h4,'position',o)
set(h3,'visible','on')
set(h,'color','w');

保存为symdisp.m,然后直接使用便有以下效果:
(注意:公式不能太长,否则无法显示完全或者会报错)
在这里插入图片描述

2.直接导出latex语句

直接使用latex函数,输出latex语句,复制粘贴到mathtype或texlive中即可
在这里插入图片描述

粘贴到mathtype
在这里插入图片描述

  • 3
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值