简体   繁体   English

在 Mathematica 中显示完整计算以复制到 Latex 中

[英]Show full calculation in Mathematica to copy into latex

I'm new to Mathematica I was hoping that this is a functionality built in. I am calculating the conditional entropy of a table and have the following 4 variables:我是 Mathematica 的新手,我希望这是一个内置功能。我正在计算表的条件熵并具有以下 4 个变量:

a = 1/8*Log[(1/8)/(1/2)] + 1/16*Log[(1/16)/(1/2)] + 1/16*Log[(1/16)/(1/2)] + 1/4*Log[(1/4)/(1/2)]

b = 1/16*Log[(1/16)/(1/4)] + 1/8*Log[(1/8)/(1/4)] + 1/32*Log[(1/32)/(1/4)] + 0

c = 1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 1/16*Log[(1/16)/(1/8)] + 0

d = 1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 0

Then the final calculation is:那么最后的计算是:

a + b + c + d

I was hoping there was a way to display the expanded a + b + c + d as a output so I can right-click/copy as latex to past into a document so I don't have to type it out.我希望有一种方法可以将扩展的a + b + c + d为输出,这样我就可以右键单击/复制作为乳胶粘贴到文档中,这样我就不必输入它了。 I can't figure out how to do it though.我不知道该怎么做。 I'm guessing there is a way to expand those variables in the output to show the full calculation but maybe it is not possible.我猜有一种方法可以在输出中扩展这些变量以显示完整的计算,但也许这是不可能的。 Thanks for any help.谢谢你的帮助。

I'm not sure how expanded you wanted the mathematical expression to be.我不确定您希望数学表达式的扩展程度如何。 See if the following expression is in the form you want to convert to LaTeX: (1/16 Log[1/(16/4)]+1/8 Log[1/(8/4)]+1/32 Log[1/(32/4)]+0)+(1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+1/16 Log[1/(16/8)]+0)+(1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+0)+(1/8 Log[1/(8/2)]+1/16 Log[1/(16/2)]+1/16 Log[1/(16/2)]+1/4 Log[1/(4/2)]) .看看下面的表达式是否是你想转换成LaTeX的形式: (1/16 Log[1/(16/4)]+1/8 Log[1/(8/4)]+1/32 Log[1/(32/4)]+0)+(1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+1/16 Log[1/(16/8)]+0)+(1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+1/32 Log[1/(32/8)]+0)+(1/8 Log[1/(8/2)]+1/16 Log[1/(16/2)]+1/16 Log[1/(16/2)]+1/4 Log[1/(4/2)])

You can get that by using HoldForm on the right-hand side of your assignments.您可以通过在作业的右侧使用 HoldForm 来获得它。 Then use TeXForm[a+b+c+d] to convert:然后使用TeXForm[a+b+c+d]进行转换:

a = HoldForm[
  1/8*Log[(1/8)/(1/2)] + 1/16*Log[(1/16)/(1/2)] + 
   1/16*Log[(1/16)/(1/2)] + 1/4*Log[(1/4)/(1/2)]];

b = HoldForm[
  1/16*Log[(1/16)/(1/4)] + 1/8*Log[(1/8)/(1/4)] + 
   1/32*Log[(1/32)/(1/4)] + 0];

c = HoldForm[
   1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 
    1/16*Log[(1/16)/(1/8)] + 0];

d = HoldForm[
   1/32*Log[(1/32)/(1/8)] + 1/32*Log[(1/32)/(1/8)] + 
    1/32*Log[(1/32)/(1/8)] + 0];

TeXForm[a + b + c + d]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM