Hi!

I know, it has been a long, long time since my last post. I would like to apologize! I have been very busy due to a massive amount of work to be done at INPE.

Anyway, this will be a very small post. I just want to update the source code of the last lesson so that it can work under **Julia v0.6** and **OrdinaryDiffEq.jl v3**.

As I said, the package **OrdinaryDiffEq.jl**, which is part of the project **JuliaDiffEq**, is amazing. In my humble opinion, one of the best open-source differential equation solvers out there. The development of this suite is occurring at a very fast rate. This is good, because the package is becoming better each day. The downside is that API changes also very fast and sometimes your code needs refactoring to continue to work in the newer versions.

# Necessary background

This is just an update of the source code presented in the last post. Hence, I highly suggest to read it first:

# Changes in OrdinaryDiffEq.jl v3

Since I posted the last tutorial, **OrdinaryDiffEq.jl** API has changed (actually, the API is defined in **DiffEqBase.jl**, but it will be updated when you update **OrdinaryDiffEq.jl**). There are three modifications that we must perform so that the previous source code works correctly with **Julia v0.6** and **OrdinaryDiffEq.jl v3.0.3**.

## Custom Data Array Interface

Previously, a custom data array interface could be created by means of a new structure that inherits the abstract type `DEDataArray{T}`

. This have changed and now the correct abstract type is `DEDataVector{T}`

. Hence, our `SimWorkspace`

definition must be:

```
type SimWorkspace{T} <: DEDataVector{T}
x::Array{T,1}
a::T
end
```

## Dynamic equation footprint

In the version used for the last tutorial, the footprint of the dynamic function was:

function f(t,u,du)

Due to some internal changes, the footprint now is:

`function f(du,u,t,p)`

`p`

is a vector of parameters that is unused in this example, but simplifies a lot of things. If you want more information, please see http://docs.juliadiffeq.org/stable/tutorials/ode_example.html#Defining-Parameterized-Functions-1.

## Callback condition function footprint

The callback condition function footprint was also changed from:

`function condition_control_loop(t,u,integrator) `

to:

`function condition_control_loop(u,t,integrator)`

# Updated source code

Finally, the updated source-code of the last tutorial can be seen below. It will provide exactly the same result.

```
using DiffEqBase
using OrdinaryDiffEq
###############################################################################
# Variables
###############################################################################
# Global variable to store the acceleration.
# This solution was selected just for the sake of simplification. Don't use
# global variables!
a = 0.0
# Parameters.
r = 10.0 # Reference position.
k = 0.3 # Proportional gain.
d = 0.8 # Derivative gain.
# Configuration of the simulation.
tf = 30.0 # Final simulation time.
tstops = collect(0:1:tf) # Instants that the control loop will be computed.
u0 = [0.0; 0.0] # Initial state.
###############################################################################
# Functions
###############################################################################
# Dynamic equation.
function dyn_eq(du,u,p,t)
du .= [0 1; 0 0]*u + [0;1]*a
end
# CALLBACK: Control loop.
# =======================
# Condition function.
function condition_control_loop(u,t,integrator)
(t in tstops)
end
# Affect function.
function control_loop!(integrator)
global a
p = integrator.u[1]
v = integrator.u[2]
a = k*(r-p) + d*(0.0-v)
end
cb = DiscreteCallback(condition_control_loop, control_loop!)
###############################################################################
# Solver
###############################################################################
prob = ODEProblem(dyn_eq, u0, (0.0, tf))
sol = solve(prob, Tsit5(), callback = cb, tstops=tstops)
nothing
```

# Conclusions

This tutorial just updated the source code of the last one so that it can work using **Julia v0.6** and **OrdinaryDiffEq.jl v3.0.3**.

I am planning for my next tutorial a simple example of how to code Kalman filters in Julia language!