# Define coupled ODE solution as differentiable

I have a variable `A` defined by an ODE, and I want to treat the solution as an explicit differentiable function of time so I can tie it in with some other code.

For example

``````m*Ä+k*A = f(A,t)
``````

where `m,k` are the mass and stiffness and `f` is the forcing giving by a coupled system of equations.

Typically, I would define the oscillator state `(A,Ȧ,t)`, and then do discrete time stepping for both systems, but this would require changing the other system quite a bit. I was hoping I could define something that acts like an explicit function so that it will play nice with `ForwardDiff` and other Julia packages.

Naively, I guess I could define a function `A(τ) = A+Ȧ(τ-t)` , and then just keep updating the internal state? Maybe this is a generator function kind of thing?

Suggestions are welcome.

1 Like

The differential equation solver is differentiable, so if you just take what comes out of the solver you should be fine?

Are you describing a symplectic integrator here? You can choose to use a symplectic integrator.

Are you describing a symplectic integrator here?

Sorry I wasn’t clear. This is a coupled fluid & structural system. The unsteady Navier-Stokes PDE for the fluid depends on the structural displacement and velocity. The structural ODE depends on the fluid force `f`. Typically, these systems are solved using a fixed-point method to update both solid and fluid states until they satisfy their GEQs and then you move on to the next time step. I’m certainly happy to hear a Julian approach to this chestnut.

The differential equation solver is differentiable, so if you just take what comes out of the solver you should be fine?

Neat! I see this bit on Interpolating. Is that what you mean? I tried to find the code for this functionality in the repo, but couldn’t track it down.