# Events that changes parameter values

**URL:** <https://discourse.julialang.org/t/events-that-changes-parameter-values/9015>\
**Category:** Modelling & Simulations\
**Created:** [February 12, 2018, 3:40pm UTC](https://discourse.julialang.org/t/events-that-changes-parameter-values/9015 "2018-02-12T15:40:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [February 12, 2018, 3:40pm UTC](https://discourse.julialang.org/t/events-that-changes-parameter-values/9015/1 "2018-02-12T15:40:22Z")

</div>

I am running simulations on chemical reaction systems. Usually for these I have some input signal and I want to investigate what happens to the system when suddenly an input is turned on. Typically I might have a variable (_X_), representing something which is produced under certain input (_i_). Typically I could model this as:  
_dX/dt = i - d\*X_  
(Then X goes on to activate some system.)  
using parameters I would express this as:  
_dX/dt = p[1] - p[2]\*X_  
Now my input is a step, so up and until some timepoint (_t0_) _i_ (that is _p[1]_) would be small, _i\_inactive_. But at time _t0_ the input becomes _i\_active_ which is some large number. How would I do to create a callback which changes the parameter value of _p[1]_ to a new value? I think I know how to use the `affect!` function to change the integrator to change the actual value of _X_, but how do I change the parameter values (the integrator seems to have no field for the parameter).

At worst I could make _i_ a second variable, which have _di/dt = 0_, and then change it via the integrator. But this do not feel like the natural solution to the problem?

---

<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:** [February 12, 2018, 3:51pm UTC](https://discourse.julialang.org/t/events-that-changes-parameter-values/9015/2 "2018-02-12T15:51:49Z")

</div>

> [@Torkel](#):
>
> I think I know how to use the affect! function to change the integrator to change the actual value of X, but how do I change the parameter values (the integrator seems to have no field for the parameter).

`integrator.p`. Note that you do need to be careful when mixing this with methods that have a lazy interpolation though, like `Vern7`.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [February 12, 2018, 3:59pm UTC](https://discourse.julialang.org/t/events-that-changes-parameter-values/9015/3 "2018-02-12T15:59:42Z")

</div>

Thank you, I will be careful (famous last words…).

---

<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:** [February 12, 2018, 4:04pm UTC](https://discourse.julialang.org/t/events-that-changes-parameter-values/9015/4 "2018-02-12T16:04:47Z")

</div>

> [@Torkel](#):
>
> Thank you, I will be careful (famous last words…).

I think it’s all but the 3 Vern algorithms (because of lazy interpolation, so only in that odd case where you’re mixing it with solving ODEs). I need to find a way to document that.

---

<div class="post-metadata">

**Author:** ![Torkel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/torkel/32/5030_2.png) [@Torkel](https://discourse.julialang.org/u/Torkel)\
**Post date:** [February 13, 2018, 4:01pm UTC](https://discourse.julialang.org/t/events-that-changes-parameter-values/9015/5 "2018-02-13T16:01:24Z")

</div>

Ok.  
in addition it seems like the .p field is not available for the `CVODE_BDF()` solver.
