# How to bring differential equations to wanted value with DiffEqFlux?

**URL:** https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167
**Category:** Numerics
**Tags:** question
**Created:** [January 29, 2021, 7:15am UTC](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167 "2021-01-29T07:15:55Z")
**Posts on this page:** 5
**Page:** 2

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [March 8, 2021, 6:47am UTC](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167/21 "2021-03-08T06:47:04Z")

</div>

I modified as you suggested, but how do I write the solver?

```julia
julia> condition1(u, t, integrator) = t==integrator.p[4] ###
condition1 (generic function with 1 method)
julia> affect1!(integrator) = integrator.u[3] += integrator.p[5] ###
affect1! (generic function with 1 method)
julia> cb1 = DiscreteCallback(condition1, affect1!)
DiscreteCallback{typeof(condition1),typeof(affect1!),typeof(DiffEqBase.INITIALIZE_DEFAULT),typeof(DiffEqBase.FINALIZE_DEFAULT)}(condition1, affect1!, DiffEqBase.INITIALIZE_DEFAULT, DiffEqBase.FINALIZE_DEFAULT, Bool[1, 1])
...
julia> prob = ODEProblem(growth!, u0, tspan, parms)
ODEProblem with uType Array{Float64,1} and tType Float64. In-place: true
timespan: (0.0, 4000.0)
u0: [1.0e7, 0.0, 0.0]

julia> EnsembleProblem(prob;
                       output_func = (sol,i) -> (sol,false),
                       prob_func= (prob,i,repeat)->(prob),
                       reduction = (u,data,I)->(append!(u,data),false),
                       u_init = [], safetycopy = prob_func !== DEFAULT_PROB_FUNC)
ERROR: UndefVarError: prob_func not defined
Stacktrace:
 [1] top-level scope at none:1

julia> solve(ensembleprob,alg,EnsembleThreads();trajectories=1000)
ERROR: UndefVarError: ensembleprob not defined
Stacktrace:
 [1] top-level scope at none:1

```

Here I think the problem is that I do not need `prob_func` but simply pass an array with the values to test for both p[4] and p[5]… How would I do that? 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: [March 8, 2021, 1:17pm UTC](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167/22 "2021-03-08T13:17:59Z")

</div>

> [@Luigi\_Marongiu](#):
>
> ```julia
> EnsembleProblem(prob;
> output_func = (sol,i) -> (sol,false),
> prob_func= (prob,i,repeat)->(prob),
> reduction = (u,data,I)->(append!(u,data),false),
> u_init = [], safetycopy = prob_func !== DEFAULT_PROB_FUNC)
> ERROR: UndefVarError: prob_func not defined
> 
> ```

Don’t copy the kwargs.

---

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [March 9, 2021, 7:22am UTC](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167/23 "2021-03-09T07:22:29Z")

</div>

I tried with:

```julia
julia> prob = ODEProblem(growth!, u0, tspan, parms)
ODEProblem with uType Array{Float64,1} and tType Float64. In-place: true
timespan: (0.0, 4000.0)
u0: [1.0e7, 0.0, 0.0]

julia> EnsembleProblem(prob;
                       output_func = (sol,i) -> (sol,false),
                       reduction = (u,data,I)->(append!(u,data),false))
EnsembleProblem with problem ODEProblem

julia> soln = solve(prob,EnsembleThreads();trajectories=1000)
retcode: Success
Interpolation: automatic order switching interpolation
t: 33-element Array{Float64,1}:
    0.0
    0.15303314059544662
...

```

Looks like it starts to work… Thank you

---

<div class="post-metadata">

### Author: ![Luigi\_Marongiu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/luigi_marongiu/32/7909_2.png) [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)
#### Post date: [April 7, 2021, 1:14pm UTC](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167/24 "2021-04-07T13:14:09Z")

</div>

An update: the process did not crash, but how should it be interpreted? I `soln` is a dataframe of 3 columns and 33 rows. Where do all the combinations come into play? If I do `EnsembleSummary(soln)` I get the error:

```julia
┌ Warning: `MonteCarloSummary(args...)` is deprecated, use `EnsembleSummary(args...)` instead.
│ caller = ip:0x0
└ @ Core :-1

```

and then the core stops the execution after few hours. The plot of `soln` columns gives:

 ![SDE](https://global.discourse-cdn.com/julialang/original/3X/5/c/5cbc2d5c20bb9cad15f5e9447ce7c67a2775114a.png)  
How shall I read the results from EnsembleProblem? 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: [April 17, 2021, 11:13am UTC](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167/25 "2021-04-17T11:13:38Z")

</div>

I have no idea what the question is. Start a new thread with an MWE.

[Previous page](https://discourse.julialang.org/t/how-to-bring-differential-equations-to-wanted-value-with-diffeqflux/54167.md?page=1)
