# ArgumentError in Fox-Rabbit Pursuit Problem with ModelingToolkit.jl

**URL:** <https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222>\
**Category:** New to Julia\
**Tags:** modelingtoolkit\
**Created:** [May 16, 2021, 1:06am UTC](https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222 "2021-05-16T01:06:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ggarza](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggarza/32/2654_2.png) [@ggarza](https://discourse.julialang.org/u/ggarza)\
**Post date:** [May 16, 2021, 1:06am UTC](https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222/1 "2021-05-16T01:06:38Z")

</div>

I am trying to solve a fox-rabbit pursuit problem with `ModelToolkit.jl`.

The fox’s path satisfies

x'(t) = R(t) (r(t) - x(t))  
y'(t) = R(t) (s(t) - y(t))

where  
R(t) = k \dfrac{\sqrt{r'(t)^2 + s'(t)^2}}{\sqrt{(r(t) - x(t))^2+(s(t) - y(t))^2}}  
and (r(t), s(t)) is the rabbit’s path.

Citation: Griffiths, D.F. and Higham, D.J., 2010. Numerical methods for ordinary differential equations: initial value problems. Springer Science & Business Media.

I’ve solved this by manually calculating (r'(t), s'(t)), but I’d rather not need to do this. Below is my first and most naive attempt. I have also tried registering the functions `r_(t)` and `s_(t)` and also extracting the derivatives `D(ra)` and `D(sa)` in the `ODESystem` by introducing new variables.

```julia
using ModelingToolkit
using DifferentialEquations

## Fox-Rabbit Pursuit
@variables t x(t) y(t) R(t) ra(t) sa(t)
@parameters k
D = Differential(t)

# rabbit's path, an outward spiral
r_(t) = sqrt(1+t) * cos(t)
s_(t) = sqrt(1+t) * sin(t)

@named rabbitfox_model = ODESystem([
    ra ~ r_(t),
    sa ~ s_(t),
    D(x) ~ R * (ra - x),
    D(y) ~ R * (sa - y),
    R ~ k * sqrt(D(ra)^2 + D(sa)^2)/
        sqrt((ra - x)^2 + (sa - y)^2)
])

prob = ODEProblem(structural_simplify(rabbitfox_model),
            [x=>3, y=>0],
            (0, 4),
            [k=>1.1]
            )

sol = solve(prob)

```

The error I get before even calling the last line is `ArgumentError: Any[ra(t), sa(t), r_(t), s_(t), R(t)] are missing from the variable map.`

I’d prefer a solution to be as close to my naive attempt as possible because it most closely matches how the problem was presented.

What do I need to change to get this to work and what am I missing?

---

<div class="post-metadata">

**Author:** ![ggarza](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggarza/32/2654_2.png) [@ggarza](https://discourse.julialang.org/u/ggarza)\
**Post date:** [May 17, 2021, 5:01pm UTC](https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222/2 "2021-05-17T17:01:10Z")

</div>

I got it to work with the following

```julia
using ModelingToolkit
using DifferentialEquations

## Fox-Rabbit Pursuit
@variables t x(t) y(t) R(t) ra(t) sa(t) dra(t) dsa(t)
@parameters k
D = Differential(t)

# rabbit's path, an outward spiral
r_(t) = sqrt(1+t) * cos(t)
s_(t) = sqrt(1+t) * sin(t)

@named rabbitfox_model = ODESystem([
    ra ~ r_(t),
    sa ~ s_(t),
    D(ra) ~ dra,
    D(sa) ~ dsa,
    D(x) ~ R * (ra - x),
    D(y) ~ R * (sa - y),
    R ~ k * sqrt(dra^2 + dsa^2)/
        sqrt((ra - x)^2 + (sa - y)^2),
])

prob = ODEProblem(structural_simplify(rabbitfox_model),
            [x=>3, y=>0, ra=>r_(0), sa=>s_(0)],
            (0, 5.071),
            [k=>1.1]
            )

sol = solve(prob)

```

Though, it seems strange to me that I need to give the initial values ` ra=>r_(0), sa=>s_(0)` for the rabbit’s path. I initially thought that these were determined somehow. It also leads to a bit of an inconsistency if we give values other than those.

---

<div class="post-metadata">

**Author:** ![YingboMa](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yingboma/32/2181_2.png) [@YingboMa](https://discourse.julialang.org/u/YingboMa)\
**Post date:** [May 17, 2021, 7:00pm UTC](https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222/3 "2021-05-17T19:00:45Z")

</div>

This might be a MTK bug. I will look into it next week. Could you file an issue as well?

---

<div class="post-metadata">

**Author:** ![ggarza](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggarza/32/2654_2.png) [@ggarza](https://discourse.julialang.org/u/ggarza)\
**Post date:** [May 19, 2021, 8:56am UTC](https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222/4 "2021-05-19T08:56:44Z")

</div>

Sure. Though, I am not quite sure how to title and phrase it as an issue. (And I’m not sure I understand what the bug is. )

I’ve posted it here: [Possible Inconsistent Initial Values of Some State Variables · Issue #1015 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/issues/1015)

---

<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:** [May 20, 2021, 11:40am UTC](https://discourse.julialang.org/t/argumenterror-in-fox-rabbit-pursuit-problem-with-modelingtoolkit-jl/61222/5 "2021-05-20T11:40:39Z")

</div>

Solved in [Possible Inconsistent Initial Values of Some State Variables · Issue #1015 · SciML/ModelingToolkit.jl · GitHub](https://github.com/SciML/ModelingToolkit.jl/issues/1015)
