从 Mathematica 到 phyton
我对 Mathematica 和 python 很陌生,但我想将 Mathematica 中的代码转录到 Sympy,因为 python 中的代码是免费的,所以我可以分享我在大学里的话,但我不明白如何开始python 中的以下代码。我希望有人能帮助我。谢谢。
定义字段。
FR[x_, y_] = Simplify[y + \[Epsilon] (a01 + a11 x + a21 y + a31 x y + a41 x^2 + a51 y^2 ) ]
GR[x_, y_] = Simplify[-x + \[Epsilon] (b01 + b11 x + b21 y + b31 x y + b41 x^2 + b51 y^2 )]
换成极坐标:
RR = FullSimplify[Collect[Factor[(Cos[\[Theta]] FR[x, y] + Sin[\[Theta]] GR[x, y]) /. {x -> r Cos[\[Theta]], y -> r Sin[\[Theta]]}], r]]
\[CapitalTheta]R = FullSimplify[Factor[((Cos[\[Theta]] GR[x, y] - Sin[\[Theta]] FR[x, y])/
r) /. {x -> r Cos[\[Theta]], y -> r Sin[\[Theta]]}]]
取泰勒级数如下式:
FFR = Simplify[Normal[Series[RR/\[CapitalTheta]R, {\[Epsilon], 0, 1}]]]
I'm very new in Mathematica and python, but I want to transcribe my code in Mathematica to Sympy because the code in python is free, and so I can to share my words of the university, But I don't understand how to begin the following code in python. I hope someone can help me. Thanks.
Define the fields.
FR[x_, y_] = Simplify[y + \[Epsilon] (a01 + a11 x + a21 y + a31 x y + a41 x^2 + a51 y^2 ) ]
GR[x_, y_] = Simplify[-x + \[Epsilon] (b01 + b11 x + b21 y + b31 x y + b41 x^2 + b51 y^2 )]
Change to polar coordinates:
RR = FullSimplify[Collect[Factor[(Cos[\[Theta]] FR[x, y] + Sin[\[Theta]] GR[x, y]) /. {x -> r Cos[\[Theta]], y -> r Sin[\[Theta]]}], r]]
\[CapitalTheta]R = FullSimplify[Factor[((Cos[\[Theta]] GR[x, y] - Sin[\[Theta]] FR[x, y])/
r) /. {x -> r Cos[\[Theta]], y -> r Sin[\[Theta]]}]]
Take the Taylor series of following expression:
FFR = Simplify[Normal[Series[RR/\[CapitalTheta]R, {\[Epsilon], 0, 1}]]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您查看 SymPy 的最新开发版本,在类
MathematicaParser
中,有一个字典 将 Mathematica 中的表达式节点映射到 SymPy 中的等效节点。这不是完整的列表,但欢迎贡献以扩展它。
SymPy 的开发版本目前能够将 Mathematica 代码解析为与其 FullForm 等效的形式,请参阅单元测试作为示例。
从现有代码开始,创建 Mathematica 到 SymPy 代码翻译器或解释器并不太难。如果有好的应用程序,这可能会成为一个不错的 Google Summer of Code (GSoC) 项目。
If you look at the latest development version of SymPy, in the class
MathematicaParser
there is a dictionary mapping the expression nodes from Mathematica to their equivalent in SymPy.It's not a complete list, but contributions are welcome to expand it.
The development version of SymPy is currently able to parse Mathematica code into a form equivalent to its FullForm, see the unit tests as an example.
Starting from the existing code, it is not too hard to create a Mathematica to SymPy code translator or interpreter. This could make for a nice Google Summer of Code (GSoC) project, if there are good applications.