Mathematica Asked by pythonuser on November 17, 2020
I want to convert a Mathematica expression that uses Root[]
to Python (open to using sympy
if needed). The expression is:
Root[-k2 k4 N0 + (B0 k2 k3 + A0 k1 k4 + k2 k4 - k2 k3 N0 -
k1 k4 N0) #1 + (A0 k1 k3 + B0 k1 k3 + k2 k3 + k1 k4 -
k1 k3 N0) #1^2 + k1 k3 #1^3 &, 3]
since FortranForm
is close to Python, I could use that and manually edit the expression. But first the Root
needs to be substituted. I tried using ToRadicals
ToRadicals[
Root[-k2 k4 N0 + (B0 k2 k3 + A0 k1 k4 + k2 k4 - k2 k3 N0 -
k1 k4 N0) #1 + (A0 k1 k3 + B0 k1 k3 + k2 k3 + k1 k4 -
k1 k3 N0) #1^2 + k1 k3 #1^3 &, 3]] // FortranForm
which gives a long expression:
-(A0*k1*k3 + B0*k1*k3 + k2*k3 + k1*k4 - k1*k3*N0)/(3.*k1*k3) +
- ((1 - (0,1)*Sqrt(3))*(-(A0*k1*k3 + B0*k1*k3 + k2*k3 + k1*k4 - k1*k3*N0)**2 + 3*k1*k3*(B0*k2*k3 + A0*k1*k4 + k2*k4 - k2*k3*N0 - k1*k4*N0)))...
but what does (0,1)*Sqrt(3)
mean in FortranForm
and what’s the correct way to write it in Python? is it just 1j*sqrt(3)
? Thanks.
A pair of real constants in parentheses represents a complex constant in Fortran, so (0,1) is the representation of Mathematica's I
, the imaginary unit.
Correct answer by John Doty on November 17, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP