# Question on how to define equation system in DiffEq using Matrix form

Hello Guys,

Previously, we handled CFD problems involving algebraic equations in the form of a matrix using a simple self-coded and stupid solver :). After reading the capability of Diffeq, we would like to move into Diffeq, and we have two questions:

1. We have the form of the ODE that is designed to solve in Diffeq. However, it is a matrix of equations instead of just a few equations. Previously, this was solved using a loop, and the coefficient in the matrix was updated correspondingly from one timestep to another. How is this accomplished in Diffeq? I can only think of including all equations into a function (using a loop), is there a more elegant way to define the problem? According to what I’ve read, Diffeq requires a function to specify the ODE equation/system and the solver for Diffeq. However, is it possible to bypass the initial step and use the ODE solver straightaway to solve my system of equations? Another way is to redefine the ODE system at every timestep, is there any computational burden for doing that, and is there a better way of achieving this?

2. Suppose we can describe the ODE system and I have an artificial source term that must be calculated in a function (which has some complex logic) at each timestep. I cannot call that function in symbolic language and that requires me again to redefine my ODE problem at every timestep. What is the proper way for revising the matrix/problem definition?

Thanks

It’s shown in the first tutorial:

https://diffeq.sciml.ai/stable/tutorials/ode_example/#ode_other_types

No, wiping the caches would make it slow.

Just make it a function of `t`, or use callbacks.

1 Like