# \[DifferentialEquations.jl\] Resolution of time variant exitation term

**URL:** <https://discourse.julialang.org/t/differentialequations-jl-resolution-of-time-variant-exitation-term/118266>\
**Category:** Modelling & Simulations\
**Created:** [August 16, 2024, 10:06am UTC](https://discourse.julialang.org/t/differentialequations-jl-resolution-of-time-variant-exitation-term/118266 "2024-08-16T10:06:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [August 16, 2024, 10:06am UTC](https://discourse.julialang.org/t/differentialequations-jl-resolution-of-time-variant-exitation-term/118266/1 "2024-08-16T10:06:55Z")

</div>

Hi all, my question may be somewhat related to this [thread](https://discourse.julialang.org/t/is-there-a-way-to-incorporate-time-series-data-into-coupled-ode-system-using-differentialequations-jl/101682).

I want to solve a FEM second-order differential equation with `DifferentialEquations.jl` using a constant and given time-step \Delta t. The problem is basically expressed as:

\mathbf{M} \ddot{\mathbf{x}}(t) + \mathbf{C}\dot{\mathbf{x}}(t) + \mathbf{Kx}(t) = \mathbf{F}(t)  
where \mathbf{M} is the mass matrix, \mathbf{C} is the damping matrix, \mathbf{K} is the stiffness matrix and \mathbf{F}(t) is the force vector.

To solve this problem with `DifferentialEquations.jl`, I have to:

- Form the corresponding first-order sytem (which is straightforward)
- Define the solver with the desired time-step. From the DiffEq doc, I think it can be implemented this way:

```julia
sol = solve(prob, Tsit5(), dt = Δt)

```

However, I don’t figure out how to use a time-variant excitation term \mathbf{F}(t), which is given as a matrix of dimensions (number of degrees of freedom)x(number of time steps). This is rather classical in the FEM softwares I use such as Nastran.

My question is, what is the recommended way to do this with `DifferentialEquations.jl`?

Should I use `DataInterpolations.jl` to transform my time series into a function and use it as in Example 3 of the [Getting started section](https://docs.sciml.ai/DiffEqDocs/stable/getting_started/) of the doc ? Or is there a more direct way ?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [August 17, 2024, 12:05pm UTC](https://discourse.julialang.org/t/differentialequations-jl-resolution-of-time-variant-exitation-term/118266/2 "2024-08-17T12:05:58Z")

</div>

> [@Maucejo](#):
>
> However, I don’t figure out how to use a time-variant excitation term \mathbf{F}(t)F(t)\mathbf{F}(t), which is given as a matrix of dimensions (number of degrees of freedom)x(number of time steps). This is rather classical in the FEM softwares I use such as Nastran.

Just make it a function call. You’re allowed to use `t` inside of the function. DataInterpolations.jl is a good choice here, since you can give it a bunch of matrices in time and then `interp(t)` will be the interpolated matrix.

Try it in a simple example first. What have you tried?

---

<div class="post-metadata">

**Author:** ![Maucejo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/maucejo/32/39090_2.png) [@Maucejo](https://discourse.julialang.org/u/Maucejo)\
**Post date:** [August 18, 2024, 7:58am UTC](https://discourse.julialang.org/t/differentialequations-jl-resolution-of-time-variant-exitation-term/118266/3 "2024-08-18T07:58:50Z")

</div>

Thank you for your answer @ChrisRackauckas. I haven’t tried to implement it yet, but I will try soon.
