Linear Time Continuous System with Controls

Now we will extend the previous example by adding some exogenous control signals. As always, we will generate some data via OrdinaryDiffEq.jl

using DataDrivenDiffEq
using LinearAlgebra
using OrdinaryDiffEq
using DataDrivenDMD
using Plots

A = [-0.9 0.2; 0.0 -0.2]
B = [0.0; 1.0]
u0 = [10.0; -10.0]
tspan = (0.0, 10.0)

f(u, p, t) = A * u .+ B .* sin(0.5 * t)

sys = ODEProblem(f, u0, tspan)
sol = solve(sys, Tsit5(), saveat = 0.05);

We will use the data provided by our problem, but add the control signal U = sin(0.5*t) to it.

X = Array(sol)
t = sol.t
control(u, p, t) = [sin(0.5 * t)]
prob = ContinuousDataDrivenProblem(X, t, U = control)
Continuous DataDrivenProblem{Float64} ##DDProblem#290 in 2 dimensions and 201 samples with controls

And plot the problems data.

plot(prob)
Example block output

Again, we will use gDMD to estimate the system dynamics. Since we have a control signal defined in the problem, the algorithm will detect it automatically and use gDMDc:

res = solve(prob, DMDSVD(), digits = 1)
"DataDrivenSolution{Float64}"

We see that the system has been recovered correctly, indicated by the small error and high AIC score of the result. We can confirm this by looking at the resulting Basis And also plot the prediction of the recovered dynamics

plot(res)
Example block output

Copy-Pasteable Code

using DataDrivenDiffEq
using LinearAlgebra
using OrdinaryDiffEq
using DataDrivenDMD

A = [-0.9 0.2; 0.0 -0.2]
B = [0.0; 1.0]
u0 = [10.0; -10.0]
tspan = (0.0, 10.0)

f(u, p, t) = A * u .+ B .* sin(0.5 * t)

sys = ODEProblem(f, u0, tspan)
sol = solve(sys, Tsit5(), saveat = 0.05);

X = Array(sol)
t = sol.t
control(u, p, t) = [sin(0.5 * t)]
prob = ContinuousDataDrivenProblem(X, t, U = control)

res = solve(prob, DMDSVD(), digits = 1)

# This file was generated using Literate.jl, https://github.com/fredrikekre/Literate.jl

This page was generated using Literate.jl.