将Mathematica方程转换为R代码 [英] Convert Mathematica equations into R code
问题描述
有没有简单的方法可以将Mathematica方程转换为R代码?我有几个方程式,其中包括数十个带有下标,上标和希腊字母的术语.例如,以下是Latex格式的一个方程式的一小部分:
Is there an easy way to convert Mathematica equations into R code? I have several equations that consist of dozens of terms with subscripts, superscripts, and greek letters. For example, here's a small part of one equation in Latex format:
m_2_2= 48 b_1 c_2^2 d_1 \rho ^4+48 b_2 c_1^2 d_2 \rho ^4+216 b_2 c_1 c_2 d_1 \rho ^3+216 b_1 c_1 c_2 d_2 \rho ^3+96 b_1 c_2^2 d_1 \rho ^2+96 b_2 c_1^2 d_2 \rho ^2 + ...
我可以从Mathematica中复制为纯文本,输入文本,Latex或MathML,但是如何使这些格式中的任何一种都能在R中与所有下标,上标和希腊语一起使用?不幸的是,这些方程是如此之长,以至于手动重新键入可能会导致错误.有什么建议吗?
I can copy from Mathematica as plain text, input text, Latex, or MathML, but how can I get any of those formats to work in R with all of the subscripts, superscripts, and greek? Unfortunately, the equations are so long that retyping manually would likely result in errors. Any suggestions?
推荐答案
内置支持将表达式导出到Fortran和C. 我建议您将表达式导出到C,然后编辑C表达式.
There is builtin support for exporting expressions to Fortran and C. I suggest you export the expression to C and then edit the C expression.
此处的详细信息: https://reference.wolfram.com/language/tutorial/GeneratingCAndFortranExpressions .html
这篇关于将Mathematica方程转换为R代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!