# Changing the shape of the initial value problem in DiffentialEquations.jl and possible performance issues

**URL:** <https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739>\
**Category:** General Usage\
**Tags:** diffeq, performance, syntax\
**Created:** [March 9, 2020, 12:04am UTC](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739 "2020-03-09T00:04:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noobie76](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@Noobie76](https://discourse.julialang.org/u/Noobie76)\
**Post date:** [March 9, 2020, 12:04am UTC](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739/1 "2020-03-09T00:04:30Z")

</div>

Dear Community

I’m not very familiar with the numerical handling of ODEs in Julia. Maybe I should begin with my goal, what I want to achieve in order to simplify the feedback loop.

I try to implement a variational solver for a one-dimensional equation (this will be extended later). Therefore I defined an ansatz u=u(x\_1,...,x\_n), let’s say all parameters in the ansatz depend on time t and this finally ends up in an evolution equation for the parameters X=(x\_1,...,x\_n) of the ansatz of the form M(X) \dot{X} = F(X). Where M(X) is a coefficient matrix with polynomial nonlinearities in the x\_i`s and F(X) is a vector-valued function of X.

Now I want to use [DifferentialEquations.jl](https://docs.juliadiffeq.org/latest/) to solve the evolution equation for the parameters and plug it into my ansatz function u. But it seems [DifferentialEquations.jl](https://docs.juliadiffeq.org/latest/) only can handle problems of the from \dot{X} = f(X, t, x) as an input.

My question is now if it is possible to change the problem shape of the input to my original system M(X) \dot{X} = F(X) or in case this is not possible do I have to expect performance losses from (some?) algorithms when I bring the system to the form \dot{X} = M(X)^{-1} F(X), where the matrix M(X)^{-1} now contains rational nonlinearities.

Cheers

---

<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:** [March 9, 2020, 12:59am UTC](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739/2 "2020-03-09T00:59:26Z")

</div>

> [@Noobie76](#):
>
> But it seems [DifferentialEquations.jl](https://docs.juliadiffeq.org/latest/) only can handle problems of the from ˙X=f(X,t,x)\dot{X} = f(X, t, x) as an input.

No, you’re looking for a mass matrix:

[https://docs.juliadiffeq.org/latest/tutorials/advanced\_ode\_example/#Handling-Mass-Matrices-1](https://docs.juliadiffeq.org/latest/tutorials/advanced_ode_example/#Handling-Mass-Matrices-1)

---

<div class="post-metadata">

**Author:** ![Noobie76](https://avatars.discourse-cdn.com/v4/letter/n/ee59a6/32.png) [@Noobie76](https://discourse.julialang.org/u/Noobie76)\
**Post date:** [March 9, 2020, 8:52am UTC](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739/3 "2020-03-09T08:52:37Z")

</div>

Thanks for your input, I’m almost at the solution to my problem. Right now I’m failing at a syntax barrier because in my case, the vector F and the matrix M both depend on the unknown vector X. By creating a system of equations like in the test example of your answer, it only sends back unknown variable errors. I just want to be securce that it is still possible to have a mass matrix depending the unknown variable? I serached the documentation but foundy any hints to my concrete problem.

Cheers

---

<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:** [March 9, 2020, 12:45pm UTC](https://discourse.julialang.org/t/changing-the-shape-of-the-initial-value-problem-in-diffentialequations-jl-and-possible-performance-issues/35739/4 "2020-03-09T12:45:33Z")

</div>

Oh you want a state-dependent mass matrix? We need to document how to do that. In the meantime, the more general form is to just use a DAE:

[https://docs.juliadiffeq.org/latest/tutorials/dae\_example/](https://docs.juliadiffeq.org/latest/tutorials/dae_example/)
