# How to print partial differential equation in desired format?

**URL:** <https://discourse.julialang.org/t/how-to-print-partial-differential-equation-in-desired-format/66411>\
**Category:** New to Julia\
**Created:** [August 14, 2021, 10:40pm UTC](https://discourse.julialang.org/t/how-to-print-partial-differential-equation-in-desired-format/66411 "2021-08-14T22:40:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rsavageatx](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rsavageatx](https://discourse.julialang.org/u/rsavageatx)\
**Post date:** [August 14, 2021, 10:40pm UTC](https://discourse.julialang.org/t/how-to-print-partial-differential-equation-in-desired-format/66411/1 "2021-08-14T22:40:59Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![genkuroki](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/genkuroki/32/18030_2.png) [@genkuroki](https://discourse.julialang.org/u/genkuroki)\
**Post date:** [August 15, 2021, 7:13am UTC](https://discourse.julialang.org/t/how-to-print-partial-differential-equation-in-desired-format/66411/2 "2021-08-15T07:13:37Z")

</div>

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

Example (from [Jupyter notebook](https://nbviewer.jupyter.org/github/genkuroki/public/blob/main/0016/SymPy%20example.ipynb))

```julia
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()

```

![image](https://global.discourse-cdn.com/julialang/original/3X/a/d/ad850ce71e5df889ddbd4d65f1bbce48e1712e5c.jpeg)

```julia
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()

```

![image](https://global.discourse-cdn.com/julialang/original/3X/d/2/d26355e1ec8d9c1cbded0c300506b4d50a681417.jpeg)

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

```julia
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

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

```

---

<div class="post-metadata">

**Author:** ![rsavageatx](https://avatars.discourse-cdn.com/v4/letter/r/ba9def/32.png) [@rsavageatx](https://discourse.julialang.org/u/rsavageatx)\
**Post date:** [August 15, 2021, 4:56pm UTC](https://discourse.julialang.org/t/how-to-print-partial-differential-equation-in-desired-format/66411/3 "2021-08-15T16:56:21Z")

</div>

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