# How to make a callback including variables in definition

**URL:** https://discourse.julialang.org/t/how-to-make-a-callback-including-variables-in-definition/34431
**Category:** Modelling & Simulations
**Tags:** diffeq
**Created:** [February 10, 2020, 7:12pm UTC](https://discourse.julialang.org/t/how-to-make-a-callback-including-variables-in-definition/34431 "2020-02-10T19:12:33Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![xixit](https://avatars.discourse-cdn.com/v4/letter/x/b9bd4f/32.png) [@xixit](https://discourse.julialang.org/u/xixit)
#### Post date: [February 10, 2020, 7:12pm UTC](https://discourse.julialang.org/t/how-to-make-a-callback-including-variables-in-definition/34431/1 "2020-02-10T19:12:33Z")

</div>

Hi, I want to make a callback function set for my differential equation. The problem is I want to make it flexible so in future I can change any desireable callback function without changing the code. It’s a simple control system with 2 inputs. I want to apply different scenarios to my model. For example in the code below, the u\_v will change from 0.0 to 0.5 in time 1800 [sec]. I cannot do it like this. previously by writing code for each scenario separately I made it correctly. But like this ☹

function TankHomogeneous(u0, scenario, timespan)  
CB = []  
for s in scenario  
if s[1]==“Tᵢ”  
if s[2]==0  
Tᵢ\_0 = s[3]  
else  
push!(CB, DiscreteCallback((u,t,integrator)-\> t==s[2], integrator → integrator.p[1]= s[3]));  
end  
elseif s[1]==“uₚ”  
if s[2]==0  
uₚ\_0 = s[3]  
else  
push!(CB, DiscreteCallback((u,t,integrator)-\> t==s[2], integrator → integrator.p[2]= s[3]));  
end  
end  
end  
# [Tᵢ\_0, uₚ\_0] is the parameters (control system inputs)  
prob1 = ODEProblem(SystemModelFunction,u0,timespan,[Tᵢ\_0, uₚ\_0],callback=**Tuple(CB)**)  
sol = solve(prob1,adaptive=false,dt=100)  
end

### then I want to pass the scenarios like this:

# each field means (“name of variable”, “time of change”, “new value”)  
scenario=[ (“uₚ”,0.0,0.0),  
(“uₚ”,1800.0,0.5),  
(“Tᵢ”,0.0,0.0)]  
u0 = 27;

TankHomogeneous(u0, scenario, (0.0,15\*3600.0))
