# How to print partial differential equation in desired format?

I am using Julia and Sympy to solve a partial differential equation and am having problems printing one of my equations in the format that I desire. This is the code that I am using:

function diffeq_3()
@vars z t
P, ∇Pk, Uk, dUdtk = symbols(“P ∇Pk Uk dUdtk”, cls = sympy.Function)
P = cos(t)*cos(z)
∇Pk = diff.(P, z)
dUdtk = diff.(Uk(z, t), t)
diffeq = Eq(dUdtk, ∇Pk)
#println(diffeq)
#solution = pdsolve(diffeq)
end

Notice that the two lines of code before the “end” statement are “commented out”. When I run diffeq_3() using Atom IDE (with Juno) I get the following differential equation in the REPL:

julia> diffeq_3()

──(Uk(z, t)) = -sin(z)⋅cos(t)
∂t

This is the format that I desire.

But when I remove the two “#” characters I get the following in the REPL:

julia> diffeq_3()
Eq(Derivative(Uk(z, t), t), -sin(z)*cos(t))
Uk(z, t) = F(z) - sin(t)⋅sin(z)

So now, the differential equation is printed as “Eq(Derivative(Uk(z, t), t), -sin(z)*cos(t))”. This
is not the format that I want. Is there a way to print the differential equation in the format that I desire and still have the “solution = pdsolve(diffeq)” statement just before the “end” statement?

You can do what you want with `display(diffeq)`.

Example (from Jupyter notebook)

``````using SymPy

function diffeq_3()
@vars z t
P, ∇Pk, Uk, dUdtk = symbols("P ∇Pk Uk dUdtk", cls = sympy.Function)
P = cos(t)*cos(z)
∇Pk = diff.(P, z)
dUdtk = diff.(Uk(z, t), t)
diffeq = Eq(dUdtk, ∇Pk)
display(diffeq)
solution = pdsolve(diffeq)
end

diffeq_3()
`````` ``````using SymPy

function diffeq_3()
@vars z t
P, ∇Pk, Uk, dUdtk = symbols("P ∇Pk Uk dUdtk", cls = sympy.Function)
P = cos(t)*cos(z)
∇Pk = diff.(P, z)
dUdtk = diff.(Uk(z, t), t)
diffeq = Eq(dUdtk, ∇Pk)
solution = pdsolve(diffeq)
[diffeq, solution]
end

diffeq_3()
`````` I prefer the latter to the former because the latter doesn’t contain the code to display. However the result of the latter is displayed in REPL as

``````2-element Vector{Sym}:
Eq(Derivative(Uk(z, t), t), -sin(z)*cos(t))
Uk(z, t) = F(z) - sin(t)*sin(z)
``````

The result of the former is displayed in REPL as

``````d
--(Uk(z, t)) = -sin(z)*cos(t)
dt
Uk(z, t) = F(z) - sin(t)*sin(z)
``````
2 Likes

genkuroki, thank you for responding to my question. The “display” command is exactly what I was looking for.