# Debugging an anonymous function passed to DynamicalSystems

**URL:** https://discourse.julialang.org/t/debugging-an-anonymous-function-passed-to-dynamicalsystems/106890
**Category:** Modelling & Simulations
**Tags:** question
**Created:** [November 29, 2023, 9:57am UTC](https://discourse.julialang.org/t/debugging-an-anonymous-function-passed-to-dynamicalsystems/106890 "2023-11-29T09:57:38Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![Datseris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/datseris/32/13406_2.png) [@Datseris](https://discourse.julialang.org/u/Datseris)
#### Post date: [November 30, 2023, 9:23am UTC](https://discourse.julialang.org/t/debugging-an-anonymous-function-passed-to-dynamicalsystems/106890/4 "2023-11-30T09:23:42Z")

</div>

> [@Niall](#):
>
> ```julia
> dynamical_rule! = function (du,u,p,t)
> for i in eachindex(p)
> p[i] = Float64(p_builder[i](p,u))
> end
> for i in 1:length(u_keys)
> du[i] = Float64(eval(du_builder[i](p,u)))
> end
> nothing
> end
> 
> ```

You cannot be changing the **parameters** of the system within the dynamical rule. The very definition of a parameter is that it does not change in time. Everything that is changing inside the dynamical rule must be a state variable, i.e., a component of `u`. You need to adjust your logical approach to the problem accordingly.

Alternatively, you can change system parameters **in-between** steps of the model. This can be done either via the callback system of DifferentialEquations.jl ([Event Handling and Callback Functions · DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/dev/features/callback_functions/) ) or by simply calling the function `set_parameter!` inbetween calls to `step!(ds::DynamicalSystem, t::Real)`.

---

_[View the full topic](https://discourse.julialang.org/t/debugging-an-anonymous-function-passed-to-dynamicalsystems/106890)._
