Skip to content

Commit c9a0e72

Browse files
committed
Jacobian support for Duffing
1 parent ba571c2 commit c9a0e72

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/famous_systems.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,26 +249,30 @@ The (forced) duffing oscillator, that satisfies the equation
249249
```
250250
with `f, ω` the forcing strength and frequency and `d` the dampening.
251251
252-
(Jacobian is computed automatically)
253-
254252
The `eom!` field of the returned system has as fields the keyword arguments of
255253
this function. You can access them and change their value at any point
256254
using `ds.eom!.parameter = value`.
257255
"""
258256
function duffing(u0 = [rand(), rand(), 0]; ω = 2.2, f = 27.0, d = 0.2)
259257
duf = Duffing(ω, d, f) # create struct
260-
return ContinuousDS(u0, duf)
258+
J = zeros(eltype(u0), 2, 2)
259+
J[1,2] = 1
260+
return ContinuousDS(u0, duf, duf, J)
261261
end
262262
mutable struct Duffing
263263
ω::Float64
264264
d::Float64
265265
f::Float64
266266
end
267-
@inbounds function (duf::Duffing)(t, u::EomVector, du::EomVector)
267+
@inbounds function (duf::Duffing)(t, u::AbstractVector, du::AbstractVector)
268268
dx[1] = x[2]
269269
dx[2] = duf.f*cos(duf.ω*t) -x[1] - x[1]^3 - duf.d * x[2]
270270
return nothing
271271
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]
275+
end
272276

273277

274278
"""

0 commit comments

Comments
 (0)