# DifferentialEquations and DAEProblem... strange error messages

**URL:** <https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210>\
**Category:** General Usage\
**Created:** [August 30, 2019, 1:48pm UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210 "2019-08-30T13:48:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 30, 2019, 1:48pm UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210/1 "2019-08-30T13:48:03Z")

</div>

OK – I used the DAE solver a year ago without problems. Now, it doesn’t work for me:

```julia
using Plots; pyplot();
using DifferentialEquations;
using Sundials;

```

If I run the example at [DAE documentation](http://docs.juliadiffeq.org/latest/tutorials/dae_example.html), there are no problems – I get the expected solution.

Next, I try to solve a simple tank model with mass balance \frac{dm}{dt} = \dot{m}\_i - \dot{m}\_e (1) where the effluent by gravity is given by some Bernoulli model, \dot{m}\_e = K\sqrt{\frac{h}{h^\varsigma}} (2), mass and volume are related by m=\rho V (3), and volume and level are related by V=Ah (4).  
So… I have a DAE with 4 equations, (1)-(4) and 4 unknowns, w = [m,V,h,\dot{m}\_e] – or `w = [m,V,h,md_e]` in Julia syntax. In addition, I have an input function \dot{m}\_i(t) which I denote `md_i(t)`, and four parameters \theta = [\rho, A, K, h^\varsigma] or `p = [rho,A,K,h_s]` in Julia.

In Julia, I specify the DAE model:

```julia
function tank(err,dw,w,p,t)
    rho,A,K,h_s = p
    m,V,h,md_e = w
    dm = dw[1]
    #
    err[1] = md_i(t) - md_e - dm
    err[2] = md_e - K*sqrt(h/h_s)
    err[3] = m-rho*V
    err[4] = V-A*h
end
#
diff_var = [true, false, false, false];
#
function md_i(t)
    return 1.5
end
;

```

Next, I define values:

```julia
# Parameters
rho = 1. # kg/L
A = 5. # dm^2
K = 3. # kg/s
h_s = 4. # dm
p = [rho,A,K,h_s]
# Initial values, etc.
h0 = 1.5 # dm
V0 = A*h0
m0 = rho*V0
md_e0 = K*sqrt(h0/h_s)
#
w0 = [m0,V0,h0,md_e0]
dw0 = [0.0,0.0,0.0,0.0]
tspan = (0.0,50.0)

```

and finally specify the problem and solve the model:

```julia
prob = DAEProblem(tank,dw0,w0,tspan,differential_vars=diff_var)
#
sol = solve(prob,IDA())

```

Instead of getting an expected solution, I get a lengthy error message…

```julia
MethodError: no method matching iterate(::Nothing)
Closest candidates are:
  iterate(!Matched::Core.SimpleVector) at essentials.jl:568
  iterate(!Matched::Core.SimpleVector, !Matched::Any) at essentials.jl:568
  iterate(!Matched::ExponentialBackOff) at error.jl:199
  ...

Stacktrace:
 [1] indexed_iterate(::Nothing, ::Int64) at .\tuple.jl:66
 [2] tank(::Array{Float64,1}, ::Array{Float64,1}, ::Array{...

```

I’m sure I’ve done a stupid mistake, but does anyone have a clue?

---

<div class="post-metadata">

**Author:** ![MatFi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/matfi/32/10002_2.png) [@MatFi](https://discourse.julialang.org/u/MatFi)\
**Post date:** [August 30, 2019, 2:07pm UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210/2 "2019-08-30T14:07:08Z")

</div>

> [@BLI](#):
>
> prob = DAEProblem(tank,dw0,w0,tspan,differential\_vars=diff\_var)

Dont now if this is important but where in prob is your `p = [rho,A,K,h_s]` ?

EDIT: Oh ist has to be `prob = DAEProblem(tank,dw0,w0,tspan,p,differential_vars=diff_var)`  
[https://github.com/JuliaDiffEq/DiffEqBase.jl/blob/master/src/problems/dae\_problems.jl](https://github.com/JuliaDiffEq/DiffEqBase.jl/blob/master/src/problems/dae_problems.jl)

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 30, 2019, 2:58pm UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210/3 "2019-08-30T14:58:07Z")

</div>

Oops. Ahem… You’re right. In the hurry, I just cloned the example on the documentation page, and didn’t think of that that example didn’t use the `p` argument…

---

<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:** [August 30, 2019, 3:58pm UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210/4 "2019-08-30T15:58:03Z")

</div>

If you update it should give you an error message about missing parameters as of last week. We found a way to throw a better message here 🙂

---

<div class="post-metadata">

**Author:** ![BLI](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bli/32/37206_2.png) [@BLI](https://discourse.julialang.org/u/BLI)\
**Post date:** [August 30, 2019, 6:00pm UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210/5 "2019-08-30T18:00:59Z")

</div>

Does it work with Julia 1.2? I haven’t upgraded yet… :-o

---

<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:** [August 31, 2019, 12:02am UTC](https://discourse.julialang.org/t/differentialequations-and-daeproblem-strange-error-messages/28210/6 "2019-08-31T00:02:27Z")

</div>

It’s also v1.1
