For the system I am using now I have data for DX so this is purely curiosity. I was thinking about a future case where I cannot define an ODE what the best way to get DX would be. I pasted an example below. Method 1 is auto detected by the source code as having a method to calculate DX, but in method 2 the source code uses interpolation via DX = Array(sol.(sol.t, Val{1})). Method 2 gives the wrong answer in this case and I was just wondering if there was a method better than interpolation but did not require you to know all of the physics behind the problem. I’m pretty sure a UDE replacing F_model is one way but I did not want to do that if it could be avoided. I also thought maybe use ApproxFun with the basis defined for the DataDrivenProblem but also wanted to see if you had any thoughts.

Thanks!

const mass = 1.0

function F_model(x, params)

return -1*(params[1] + 2*params[2]**x + 3*params[3](x^2) + 4*params[4]*(x^3))

end

function newton(u,p,t)

x, v = u

dx = v

dv = (1/mass)*F_model(x,p)

return [dx, dv]

end

u0 = [1.0;0.0]

tspan = (0.0,2.0)

dt = 0.01

true_params = [1.469,-2*0.057,0.0,0.0]

prob = ODEProblem(newton,u0,tspan,true_params)

sol = solve(prob, Tsit5(), saveat = dt)

Method 1: Using ODE to get DX

ddprob = DataDrivenProblem(sol)

@variables t x(t) v(t)

u = [x; v]

basis = Basis(polynomial_basis(u, 5), u, iv = t)

opt = STLSQ(exp10.(-10:0.1:-1))

ddsol = solve(ddprob, basis, opt, options = DataDrivenCommonOptions(digits = 1))

println(get_basis(ddsol))

Method 2: Interpolation

X = Array(sol)

ddprob = ContinuousDataDrivenProblem(X, sol.t)

@variables t x(t) v(t)

u = [x; v]

basis = Basis(polynomial_basis(u, 5), u, iv = t)

opt = STLSQ(exp10.(-10:0.1:-1))

ddsol = solve(ddprob, basis, opt, options = DataDrivenCommonOptions(digits = 1))

println(get_basis(ddsol))