# Draw Parametric Equations from dsolve of SymPy with Plots

**URL:** <https://discourse.julialang.org/t/draw-parametric-equations-from-dsolve-of-sympy-with-plots/97270>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [April 9, 2023, 6:38am UTC](https://discourse.julialang.org/t/draw-parametric-equations-from-dsolve-of-sympy-with-plots/97270 "2023-04-09T06:38:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [April 9, 2023, 6:38am UTC](https://discourse.julialang.org/t/draw-parametric-equations-from-dsolve-of-sympy-with-plots/97270/1 "2023-04-09T06:38:38Z")

</div>

Hi all,

I want to draw parametric equations of x(t), y(t) but I got errors:  
**LoadError: AssertionError: !(F2 \<: Function || F2 \<: AbstractArray && F2.parameters[1] \<: Function)**

if I try

```julia
plot(f,g)

```

I got the same error:  
**AssertionError: !(F2 \<: Function || F2 \<: AbstractArray && F2.parameters[1] \<: Function)**

This is the full code:

```julia
using SymPy, Plots, LaTeXStrings, Plots.PlotMeasures
@syms t, g, r, A, u, h
@syms v()
@syms w()
@syms x()
@syms y()

# Computing IVP with SymPy
diffeqv = Eq(v(t).diff(t), -r*v(t)); string(diffeqv)
diffeqw = Eq(w(t).diff(t), -g -r*w(t)); string(diffeqw)

# To solve the ODE, pass it and the function to solve with dsolve.
vt = dsolve(diffeqv, v(t))
wt = dsolve(diffeqw, w(t))

sol_vt = rhs(vt)
sol_wt = rhs(wt)

# To solve the Initial Value Problem, initial condition v(0) = u cos (A)
ivp_vt = dsolve(diffeqv, v(t), ics = Dict(v(0) => u*cos(A) ))
ivp_wt = dsolve(diffeqw, w(t), ics = Dict(w(0) => u*sin(A) ))

# Manual way
# Find the constant C₁
c1 = free_symbols(vt)[1]
# To solve the Initial Value Problem, initial condition v(0) = u cos (A)
C1 = solve(sol_vt(t=>0) ~ u*cos(A), c1)
#ivp_vt = sol_vt(c1=>C1[1])

# Part (b)
diffeqx = Eq(x(t).diff(t), rhs(ivp_vt));
diffeqy = Eq(y(t).diff(t), rhs(ivp_wt));

# To solve the ODE, pass it and the function to solve with dsolve.
xt = dsolve(diffeqx, x(t))
yt = dsolve(diffeqy, y(t))

sol_xt = rhs(xt)
sol_yt = rhs(yt)
ivp_xt = dsolve(diffeqx, x(t), ics = Dict(x(0) => 0 ))
ivp_yt = dsolve(diffeqy, y(t), ics = Dict(y(0) => h ))

println("Modeling with First Order Equations with Julia")
println("A baseball is thrown with the initial speed of u and initial angle of elevation is A")
println("v(t) is the horizontal component of the velocity of the thrown baseball")
println("w(t) is the vertical component of the velocity of the thrown baseball")
println("x(t) is the horizontal coordinate of the thrown baseball at time t")
println("y(t) is the vertical coordinate of the thrown baseball at time t")

println("")
println("The horizontal and vertical coordinates plot: ")

f = ivp_xt(u => 125, r => 1/5, A => pi/2)
g = ivp_yt(u => 125, r => 1/5, A => pi/2, g => 32, h => 3)

t = 0:0.1:100π
plot(f,g,
	legend=:topright, bottom_margin=5mm, 
	left_margin=5mm,
	xlabel="time (seconds)", ylabel="coordinate (ft)",
	label=L" x(t), y(t) = \frac{u}{r} \cos \ A (1 - e^{-rt}), - \frac{gt}{r} + \frac{g + ur \ \sin \ A + hr^{2}}{r^{2}} - (\frac{u}{r} \ \sin \ A + \frac{g}{r^{2}})e^{-rt} ", 
	xformatter = x->string(Int(x/1)," "),
	size=(720, 360), tickfontsize=10)

```

The plot should look like this more or less:  
 ![Capture d’écran_2023-04-09_13-38-21](https://global.discourse-cdn.com/julialang/original/3X/9/3/93ed0602dbcb474d570c2578b29c3a2c3f0b4fdc.png)

---

<div class="post-metadata">

**Author:** ![j\_verzani](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/j_verzani/32/8551_2.png) [@j\_verzani](https://discourse.julialang.org/u/j_verzani)\
**Post date:** [April 9, 2023, 11:34am UTC](https://discourse.julialang.org/t/draw-parametric-equations-from-dsolve-of-sympy-with-plots/97270/2 "2023-04-09T11:34:54Z")

</div>

I didn’t check your math, but you need to call `rhs` on `f` and `g` to work with them as symbolic expressions.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [April 9, 2023, 12:24pm UTC](https://discourse.julialang.org/t/draw-parametric-equations-from-dsolve-of-sympy-with-plots/97270/3 "2023-04-09T12:24:12Z")

</div>

Yes, on that I have tried to create a new code just to plot but still didn’t make it, parametric equations on x(t), y(t) is quite a hell

```julia
using SymPy, Plots, LaTeXStrings, Plots.PlotMeasures

gr()
u = 125
r = 1/5
h = 3
A = 25
g = 32

#int = range(0, stop=10, length=300)
int = 0:0.1:10.1π
x(t) = (u/r)*cos(A) - (u/r)*exp(-r*t)*cos(A)
y(t) = -(g*t/r) - (g/r^2)*exp(-r*t) - (u/r)*exp(-r*t)*sin(A) + (g + h*r^2 + r*u*sin(A))/(r^2)
# note the dot, which means compute x for all values in the int range
plot(x.(int),y.(int),
	label=L"x(t),y(t) = \frac{u}{r} \cos \ A (1 - e^{-rt}) , - \frac{gt}{r} + \frac{g + ur \ \sin \ A + hr^{2}}{r^{2}} - (\frac{u}{r} \ \sin \ A + \frac{g}{r^{2}})e^{-rt}",
	legend=:outerbottom)
# plot(x,y,0,2π)
#plot(x,y,0,248π,1000)
#plot(x,y,0,248π,10_000)

```

I will try your suggestion then. Thanks

![Capture d’écran_2023-04-09_19-50-06](https://global.discourse-cdn.com/julialang/original/3X/b/0/b0a369b4d29a0c297194711958180a213b512d82.png)
