# How to Draw This Spiral Solution Curve?

Hi all,

I read this topic and it is still confusing since the differential equation is a bit different:

I use only variable of t. That topic use dx/dt and dy/dt, thus I can’t really use it to my problem at hand.

This is the problem, and the solution. What I want to achieve is how to plot the spiral curve along with the arrow? Given the input of matrix A and the initial value x(0).

Something is weird with this example. At x0 the derivative is [-2,1] but the spiral curve clearly shows something like [0,1]. I haven’t looked carefully but perhaps this is just a poor drawing?

The solution curve is for the solution:

\boldsymbol{x} (t) = e^{-2t}[\cos t \ \sin \ t]

with x_{1} (t) = e^{-2t} \cos \ t and x_{2} (t) = e^{-2t} \sin \ t

now if we put the t=0 (at the beginning) we will obtain:
x_{1} (0) = e^{-0} \cos \ 0 and x_{2} (0) = e^{-0} \sin \ 0

which will become the initial coordinate for the solution curve of

\boldsymbol{x} (t) = e^{-0}[\cos 0 \ \sin \ 0] = 1[1 \ 0]

thus the coordinate is (1,0) at the beginning and x-axis is the x_{1} and y-axis is the x_{2} that is why the arrow is pointing to that way. the term e^{-2t} wil goes to 0 as t goes to infinity… that is why it is spiraling to (0,0).

That is from my understanding. Correct me if I am wrong… I know there are lots of silent reader who is an expert / more than PhDs here…

The problem is I want to draw the solution curve…

Can anyone help? Or just pray I can make it alone…
either way thanks folks! or aliens or vampires here…

Plotting the solution given the formula is pretty straightforward.

ts=0.0:.01:5.0

x=[exp(-2*t) cos(t) for t in ts]
y=... Etc

plot(x,y)


After see this: parametric function plot 3d | [“Julia Plots Gallery”]
I try this code:


using MTH229, ForwardDiff, Plots, LaTeXStrings, SymPy
gr()

t = range(0, stop=10, length=1000)
x = e^(-2t)*cos.(t)
y = e^(-2t)*sin.(t)

plot(x, y)



but it won’t work:

ERROR: LoadError: MethodError: no method matching ^(::Float64, ::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64})
Closest candidates are:
^(::Number, ::Missing) at ~/julia-1.7.3/share/julia/base/missing.jl:124
^(::T, ::Rational) where T<:AbstractFloat at ~/julia-1.7.3/share/julia/base/rational.jl:480
^(::AbstractFloat, ::ForwardDiff.Dual{Ty}) where Ty at ~/.julia/packages/ForwardDiff/eqMFf/src/dual.jl:145

Stacktrace:
[1] top-level scope
@ ~/LasthrimProjection/plot.jl:6
[2] include(fname::String)
@ Base.MainInclude ./client.jl:451
[3] top-level scope
@ REPL[1]:1
in expression starting at /home/browni/LasthrimProjection/plot.jl:6

You’re basically trying to take the exponential of a vector, which is undefined. Try

x = exp.(-2t)*cos.(t)


or, which is equivalent,

x = @. exp(-2t)*cos(t)


so that the exponential function acts element-wise.

Wait I fot it works by using GoroPikari example:


using MTH229, ForwardDiff, Plots, LaTeXStrings, SymPy
gr()

xₜ(t) = exp(-2t)*cos(t)
yₜ(t) = exp(-2t)*sin(t)

plot(xₜ, yₜ, 0, 2π, leg=false)


but the question is how to make the small circle goes to (0,0) ? and the quiver or arrow…

Alright this code works:

t = range(0, stop=10, length=1000)
x = @. exp(-2t)*cos(t)
y = @. exp(-2t)*sin(t)

plot(x, y)



but how to create the small circle rotating to (0,0) again plus the arrow?

This looks better:

t = range(0, stop=21, length=10000)
x = @. exp(-2t)*cos(t)
y = @. exp(-2t)*sin(t)

plot(x, y,xlims=(-0.1,1), ylims=(-0.1,0.21))



I see this CalculusWithJulia’ arrow feature, but it is straight line, how to bend it?

The solution looks different from the cartoon…

Anyway, you can plot the solution as two parts, one of which has an arrow:

x1(t) = exp(-2t)*cos(t)
x2(t) = exp(-2t)*sin(t)

plot(x1, x2, 0, π/6, legend=false, color=:black, arrow=true)
plot!(x1, x2, π/6, 2π, legend=false, color=:black)

1 Like

Yes it works, anyway thanks a lot, now just thinking how to make the small spiraling to (0,0)… or zoom it in

It reaches 0,0 when t goes to infinity…

The real solution is different from the cartoon. If you want something more like the cartoon try changing the exponential to be a smaller power… exp(-t/2) for example

1 Like

Alright then I will try it, so the textbook gives me bias then.