I try to use the Wolfram Python client library to evaluate a differential equation in Python.
This does not work smoothly, but using
from wolframclient.evaluation import WolframLanguageSession
from wolframclient.language import wl, wlexpr
session = WolframLanguageSession()
with WolframLanguageSession() as s:
result = s.evaluate_wrap("TexForm[DSolve[y'[x] + y[x] == 0, y[x], x][[1, 1, 2]]]")
As you see, I already tried to bring DSolve into TexForm in this expression to be able to read it in Python.
But with using TexForm or without I get something like
(With TexForm)
Global`TexForm[Times[Power[E, Times[-1, Global`x]], C[1]]]
(Without TexForm)
Times[Power[E, Times[-1, Global`x]], C[1]]
How can I bring that into a form, that I can use in Python, i.e. in sympy or even a LaTex String?
CForm
? That givesC(1)/Power(E,x)
. $\endgroup$CForm[Times[Power[E, Times[-1, Global`x]], C[1]]]
for that. Although it evaluates well in Mathematica. $\endgroup$result = s.evaluate("DSolve[y'[x] + y[x] == 0, y[x], x][[1, 1, 2]]".encode('ascii'))
but that just returned a string back, not an expression. I think there's a bug here, because I can't seem to do anyDSolve
's. Other functions likeSolve[x^2==3,x]
work fine. $\endgroup$(First[y[x] /. (DSolve[{y'[x] + y[x] == 0, y[0] == 1}, y[x], x])])//InputForm
to eliminate the[[1,1,2]]
, added an initial condition, and useInputForm
in case the generated parameter was the problem. But it still fails. $\endgroup$Times[Power[E, Times[-1, Global`x]], C[1]]
? All I get isString expected at position 1 in StringForm[MessageName[General, pkspec1], Slot[1]]
$\endgroup$