# Exercise in DiffEqTutorials, "Failed to build the parameter derivatives"

**URL:** <https://discourse.julialang.org/t/exercise-in-diffeqtutorials-failed-to-build-the-parameter-derivatives/32711>\
**Category:** General Usage\
**Created:** [December 26, 2019, 9:46am UTC](https://discourse.julialang.org/t/exercise-in-diffeqtutorials-failed-to-build-the-parameter-derivatives/32711 "2019-12-26T09:46:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![yuxi.liu](https://avatars.discourse-cdn.com/v4/letter/y/839c29/32.png) [@yuxi.liu](https://discourse.julialang.org/u/yuxi.liu)\
**Post date:** [December 26, 2019, 9:46am UTC](https://discourse.julialang.org/t/exercise-in-diffeqtutorials-failed-to-build-the-parameter-derivatives/32711/1 "2019-12-26T09:46:52Z")

</div>

This is from the tutorial of DiffEqTutorials, [Callbacks and Events](https://tutorials.juliadiffeq.org/html/introduction/04-callbacks_and_events.html), exercise 2:

```julia
using DifferentialEquations, ParameterizedFunctions
ball! = @ode_def BallBounce begin
  dy = v
  dv = -g + k*v
end g e k

```

throws error  
`┌ Warning: Failed to build the parameter derivatives.`

This error, whatever it is, causes DiscreteCallback to not work.  
Only the ground callback is still working.

```julia
u0 = [50.0,0.0] # height, velocity
tspan = (0.0,15.0)
p = (9.8, 0.9, 0.0)

function condition_ground(u,t,integrator)
    u[1] # height at zero
end
function affect_ground!(integrator)
    integrator.u[2] = -integrator.p[2] * integrator.u[2]
end
bounce_cb = ContinuousCallback(condition_ground,affect_ground!)

function condition_kick(u,t,integrator)
    t === 2
end
function affect_kick!(integrator)
    integrator.u[2] += 50
end
kick_cb = DiscreteCallback(condition_kick,affect_kick!)

function condition_wind(u,t,integrator)
    t === 10
end
function affect_wind!(integrator)
    integrator.p[3] += 50
end
wind_cb = DiscreteCallback(condition_wind,affect_wind!)

cb = CallbackSet(bounce_cb,kick_cb, wind_cb);

prob = ODEProblem(ball!,u0,tspan,p,callback=cb)
sol = solve(prob,Tsit5(),tstops=[2.0, 10.0])
plot(sol)

```

 ![](https://global.discourse-cdn.com/julialang/original/3X/0/9/09d87575dc1b7f3f1bf9b227edb8516b82106ee3.png)

---

<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:** [December 26, 2019, 12:42pm UTC](https://discourse.julialang.org/t/exercise-in-diffeqtutorials-failed-to-build-the-parameter-derivatives/32711/2 "2019-12-26T12:42:53Z")

</div>

> [@yuxi.liu](#):
>
> ┌ Warning: Failed to build the parameter derivatives.

That’s completely harmless since you’re not doing sensitivity analysis. ParameterizedFunctions.jl will soon be removed from all tutorials.

For this, your main issue was the use of `===` which was causing the scalar checks to not return true. To check whether two numbers are the same, use `==`. Other than that, your wind resistance was huge and it wasn’t resistance, it was wind acceleration! You can analytically calculate why it would explode given your model, so that should be changed to be something like a negative. Also, your parameters needs to be a mutable container if you’re going to mutate them, so using a parameter vector is wise.

Here’s a working solution:

```julia
using DifferentialEquations, ParameterizedFunctions
ball! = @ode_def BallBounce begin
  dy = v
  dv = -g + k*v
end g e k

u0 = [50.0,0.0] # height, velocity
tspan = (0.0,15.0)
p = [9.8, 0.9, 0.0]

function condition_ground(u,t,integrator)
    u[1] # height at zero
end
function affect_ground!(integrator)
    integrator.u[2] = -integrator.p[2] * integrator.u[2]
end
bounce_cb = ContinuousCallback(condition_ground,affect_ground!)

function condition_kick(u,t,integrator)
    t == 2
end
function affect_kick!(integrator)
    integrator.u[2] += 50
end
kick_cb = DiscreteCallback(condition_kick,affect_kick!)

function condition_wind(u,t,integrator)
    t == 10
end
function affect_wind!(integrator)
    integrator.p[3] -= 1
end
wind_cb = DiscreteCallback(condition_wind,affect_wind!)

cb = CallbackSet(bounce_cb,kick_cb, wind_cb);

prob = ODEProblem(ball!,u0,tspan,p,callback=cb)
sol = solve(prob,Tsit5(),tstops=[2.0, 10.0])
plot(sol)

```

![superball](https://global.discourse-cdn.com/julialang/original/3X/6/f/6fb90eb460d2198bfb5c2e90a697b25fd2ed23fc.png)
