# DiffEq result for a dynamical system differs from wolframalpha

**URL:** <https://discourse.julialang.org/t/diffeq-result-for-a-dynamical-system-differs-from-wolframalpha/45101>\
**Category:** Modelling & Simulations\
**Created:** [August 17, 2020, 10:52am UTC](https://discourse.julialang.org/t/diffeq-result-for-a-dynamical-system-differs-from-wolframalpha/45101 "2020-08-17T10:52:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Qfl3x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qfl3x/32/16227_2.png) [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Post date:** [August 17, 2020, 10:52am UTC](https://discourse.julialang.org/t/diffeq-result-for-a-dynamical-system-differs-from-wolframalpha/45101/1 "2020-08-17T10:52:26Z")

</div>

I want to solve this differential equation:

(d^2 y(t))/(dt^2) = -0.1×(dy(t))/(dt) + 0.5 y(t) - 2 y(t)^3 + 2 cos(2.4 t)

How I tried to solve it using DiffEq:

```julia
using DifferentialEquations
using Plots

function duffing!(du,u,p,t)
    du[1]=u[2]
    du[2]=-p[1]*u[2] + 2*p[2] * u[1] - 4*p[3]*(u[1])^3 + p[4] * cos(p[5]*t)
end

function Duffing(x0,xx0,F0,ω,γ,max_k=5000,m=1,a=0.25,b=0.5)
    u0=[x0,xx0]
    tspan=(0.0,max_k*2*pi/ω)
    p=[γ,a,b,F0,ω]
    prob=ODEProblem(duffing!,u0,tspan,p)
    return solve(prob,DPRKN6(),saveat=pi/ω)
end

function plotter(x0,xx0,F0,ω,γ,max_k)
    closeall()
    sol=Duffing(x0,xx0,F0,ω,γ,max_k)
    x_arr=[];xx_arr=[];
    period=2*pi/ω
    for k=0:max_k
        pair=sol(k*period)
        x_arr=push!(x_arr,pair[1])
        xx_arr=push!(xx_arr,pair[2])
    end
    scatter(x_arr,xx_arr,markersize=0.8,label="")
    #savefig("img.png")
end

```

However, what I get looks like a [big clump](https://i.imgur.com/R30ak7x.png) rather than [what wolframalpha gives out](https://www.wolframalpha.com/input/?i=d%5E2y%2Fdt%5E2%3D-0.1*dy%2Fdt+%2B0.5*y-2*y%5E3%2B2*cos%282.4*t%29). It doesn’t look like my system is chaotic but rather goes towards a fixed point.

EDIT:[What the Book says I should get for the same conditions as the figure above](https://i.imgur.com/3pELZG9.png)

---

<div class="post-metadata">

**Author:** ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)\
**Post date:** [August 17, 2020, 11:29am UTC](https://discourse.julialang.org/t/diffeq-result-for-a-dynamical-system-differs-from-wolframalpha/45101/2 "2020-08-17T11:29:56Z")

</div>

We have an example of the stroboscopic map of the duffing system in the DynamicalSystems.jl documentation, and it shows the chaotic attractor without a problem: [Orbit Diagrams & PSOS · DynamicalSystems.jl](https://juliadynamics.github.io/DynamicalSystems.jl/dev/chaos/orbitdiagram/#Stroboscopic-Map-1)

And the way we define the dynamical rule is as follows:

[https://github.com/JuliaDynamics/DynamicalSystemsBase.jl/blob/master/src/continuous\_famous\_systems.jl#L380](https://github.com/JuliaDynamics/DynamicalSystemsBase.jl/blob/master/src/continuous_famous_systems.jl#L380)

(`trajectory` is just a wrapper around `solve` that explicitly gives `saveat`)

my equations are slightly different than yours, because I use the out of place form (recommended for small systems). I also use slightly different parameters, but that shouldn’t matter. Perhaps check your code for typos? Also, does `DPRKN6()` allow interpolation? (since the syntaxx `sol(some_time)` interpolates)

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 17, 2020, 12:28pm UTC](https://discourse.julialang.org/t/diffeq-result-for-a-dynamical-system-differs-from-wolframalpha/45101/3 "2020-08-17T12:28:56Z")

</div>

> [@Datseris](#):
>
> Also, does `DPRKN6()` allow interpolation?

Yes

---

<div class="post-metadata">

**Author:** ![Qfl3x](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/qfl3x/32/16227_2.png) [@Qfl3x](https://discourse.julialang.org/u/Qfl3x)\
**Post date:** [August 17, 2020, 1:38pm UTC](https://discourse.julialang.org/t/diffeq-result-for-a-dynamical-system-differs-from-wolframalpha/45101/4 "2020-08-17T13:38:52Z")

</div>

It appears the problem is [solved](https://i.imgur.com/FZ1A9U8.png) if I change the constants. Perhaps the book is wrong (Thijssen Comp. Phys.).
