# Question about DiffEqOperators

**URL:** https://discourse.julialang.org/t/question-about-diffeqoperators/14242
**Category:** General Usage
**Tags:** diffeq
**Created:** [August 29, 2018, 1:38pm UTC](https://discourse.julialang.org/t/question-about-diffeqoperators/14242 "2018-08-29T13:38:57Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![jtravs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jtravs/32/2010_2.png) [@jtravs](https://discourse.julialang.org/u/jtravs)
#### Post date: [August 29, 2018, 1:38pm UTC](https://discourse.julialang.org/t/question-about-diffeqoperators/14242/1 "2018-08-29T13:38:58Z")

</div>

I’m interested in possibly using the [DiffEqOperators](http://docs.juliadiffeq.org/latest/features/diffeq_operator.html#Using-DiffEqOperators-1) functionality in DifferentialEquations.jl

I usually solve systems of nonlinear equations that are of the form

\frac{\partial A}{\partial z} = i\beta(z) A + F(A,z)

where A and \beta are complex arrays (i.e. \beta is a linear operator), and F is some nonlinear function of A. The way I do this is to transform the above into

\frac{\partial G}{\partial z} = e^{-i\beta (z) z}F(A,z)

with

G = e^{-i\beta (z) z}A

And I have to transform back at each step to calculate F, and also transform back from G to A when saving the solution. Note that in general \beta depends on z, and so the operator needs to be updated as the integration progresses.

I currently solve the above by using the iterator interface to DifferentialEquations.jl, and mutating `u` after each step to reset it to A, before optionally saving and continuing. I get good performance from the `Tsit5` algorithm, and I’m very happy (compared to when I was hand writing my own ODE solvers in C++).

However, I noticed the page on [DiffEqOperators](http://docs.juliadiffeq.org/latest/features/diffeq_operator.html#Using-DiffEqOperators-1) and wondered if that interface is designed to solve exactly this kind of problem?

Any tips?

---

<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 29, 2018, 1:45pm UTC](https://discourse.julialang.org/t/question-about-diffeqoperators/14242/2 "2018-08-29T13:45:34Z")

</div>

> [@jtravs](#):
>
> However, I noticed the page on [DiffEqOperators](http://docs.juliadiffeq.org/latest/features/diffeq_operator.html#Using-DiffEqOperators-1) and wondered if that interface is designed to solve exactly this kind of problem?

Yes, it’s exactly for this kind of problem. More specifically, we have ExponentialUtilities.jl for doing the Krylov approximation to the matrix exponential

> **[GitHub - SciML/ExponentialUtilities.jl: Fast and differentiable...](https://github.com/SciML/ExponentialUtilities.jl)**
>
> Fast and differentiable implementations of matrix exponentials, Krylov exponential matrix-vector multiplications ("expmv"), KIOPS, ExpoKit functions, and more. All your exponential needs ...

and then utilize this in the semilinear exponential integrators.

[http://docs.juliadiffeq.org/latest/solvers/split\_ode\_solve.html#Semilinear-ODE-1](http://docs.juliadiffeq.org/latest/solvers/split_ode_solve.html#Semilinear-ODE-1)

---

<div class="post-metadata">

### Author: ![jtravs](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jtravs/32/2010_2.png) [@jtravs](https://discourse.julialang.org/u/jtravs)
#### Post date: [August 29, 2018, 3:25pm UTC](https://discourse.julialang.org/t/question-about-diffeqoperators/14242/3 "2018-08-29T15:25:46Z")

</div>

Thanks!

Can I ask if these methods are efficient for diagonal operators (which is my case)? For example is the `diagonal` trait from `LinearMaps.jl` used? Regardless, I will give this a try.

Are there any examples anywhere of how to pull all of the pieces together?

Thanks!

---

<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 29, 2018, 3:45pm UTC](https://discourse.julialang.org/t/question-about-diffeqoperators/14242/4 "2018-08-29T15:45:18Z")

</div>

> [@jtravs](#):
>
> Can I ask if these methods are efficient for diagonal operators (which is my case)? For example is the `diagonal` trait from `LinearMaps.jl` used? Regardless, I will give this a try.

If you make an array operator where it’s a `Diagonal` matrix then it will make use of the overloads. There is more we should be doing like this. We don’t have such a trait to generalize it to matrix-free operations yet or anything like that.

> [@jtravs](#):
>
> Are there any examples anywhere of how to pull all of the pieces together?

There’s some random tests around

> <https://gist.github.com/ChrisRackauckas/ddbeac88cdaa779c8da991f66e1c3823>

But we really need to get a whole tutorial series out for it. There’s still some more on the API we want to settle first though.
