Skip to content

Commit 60309a0

Browse files
committed
Parameters in DUffing and works
1 parent c9a0e72 commit 60309a0

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/famous_systems.jl

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,19 @@ end
242242

243243

244244
"""
245-
duffing(u0 = [rand(), rand(), 0]; ω = 2.2, f = 27.0, d = 0.2)
245+
duffing(u0 = [rand(), rand(), 0]; ω = 2.2, f = 27.0, d = 0.2, β = 1)
246246
The (forced) duffing oscillator, that satisfies the equation
247247
```math
248-
\\ddot{x} + d\\cdot\\dot{x} + x + x^3 = f\\cos(\\omega t)
248+
\\ddot{x} + d\\cdot\\dot{x} + β*x + x^3 = f\\cos(\\omega t)
249249
```
250250
with `f, ω` the forcing strength and frequency and `d` the dampening.
251251
252252
The `eom!` field of the returned system has as fields the keyword arguments of
253253
this function. You can access them and change their value at any point
254254
using `ds.eom!.parameter = value`.
255255
"""
256-
function duffing(u0 = [rand(), rand(), 0]; ω = 2.2, f = 27.0, d = 0.2)
257-
duf = Duffing(ω, d, f) # create struct
256+
function duffing(u0 = [rand(), rand()]; ω = 2.2, f = 27.0, d = 0.2, β = 1)
257+
duf = Duffing(ω, d, f, β) # create struct
258258
J = zeros(eltype(u0), 2, 2)
259259
J[1,2] = 1
260260
return ContinuousDS(u0, duf, duf, J)
@@ -263,15 +263,16 @@ mutable struct Duffing
263263
ω::Float64
264264
d::Float64
265265
f::Float64
266+
β::Float64
266267
end
267-
@inbounds function (duf::Duffing)(t, u::AbstractVector, du::AbstractVector)
268+
@inbounds function (duf::Duffing)(t, x::AbstractVector, dx::AbstractVector)
268269
dx[1] = x[2]
269-
dx[2] = duf.f*cos(duf.ω*t) -x[1] - x[1]^3 - duf.d * x[2]
270+
dx[2] = duf.f*cos(duf.ω*t) - duf.β*x[1] - x[1]^3 - duf.d * x[2]
270271
return nothing
271272
end
272-
@inbounds function (duf::Duffing)(t, u::AbstractVector, du::AbstractMatrix)
273-
J[2,1] = -1 - 3u[1]^2
274-
J[2,2] = - duf.d*u[2]
273+
@inbounds function (duf::Duffing)(t, u::AbstractVector, J::AbstractMatrix)
274+
J[2,1] = -duf.β - 3u[1]^2
275+
J[2,2] = -duf.d*u[2]
275276
end
276277

277278

0 commit comments

Comments
 (0)