# ModelingToolkit: how to get variable index of ODE solution as interpolating function

**URL:** https://discourse.julialang.org/t/modelingtoolkit-how-to-get-variable-index-of-ode-solution-as-interpolating-function/64999
**Category:** General Usage
**Created:** [July 20, 2021, 5:52pm UTC](https://discourse.julialang.org/t/modelingtoolkit-how-to-get-variable-index-of-ode-solution-as-interpolating-function/64999 "2021-07-20T17:52:46Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Egwene\_al\_Vere](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)
#### Post date: [July 20, 2021, 5:52pm UTC](https://discourse.julialang.org/t/modelingtoolkit-how-to-get-variable-index-of-ode-solution-as-interpolating-function/64999/1 "2021-07-20T17:52:47Z")

</div>

Since the ordering of symbols is not guaranteed, the solution of ode’s from ModelingToolkit is usually accessed by name. However, `sol[foo]` only gives a vector (against sol.t). How to find the index of some variable `foo` in the solutions’s interpolating function interface `sol(t)`? example from [doc](https://mtk.sciml.ai/stable/tutorials/higher_order/):

```julia
using ModelingToolkit, OrdinaryDiffEq

@parameters t σ ρ β
@variables x(t) y(t) z(t)
D = Differential(t)

eqs = [D(D(x)) ~ σ*(y-x),
       D(y) ~ x*(ρ-z)-y,
       D(z) ~ x*y - β*z]

sys = ODESystem(eqs)
sys = ode_order_lowering(sys)

u0 = [D(x) => 2.0,
      x => 1.0,
      y => 0.0,
      z => 0.0]

p = [σ => 28.0,
      ρ => 10.0,
      β => 8/3]

tspan = (0.0,100.0)
prob = ODEProblem(sys,u0,tspan,p,jac=true)
sol = solve(prob,Tsit5())

```

how do I get the index of, say, the index of `x` from e.g. `sol(1.2)`? Looks like the [faq](https://mtk.sciml.ai/stable/basics/FAQ/#Getting-the-index-for-a-symbol)’s index finding applies only to parameters and not on the ODESolution object.

Thanks!

Edit: looks like `sys.states` gives a vector of `Term`, one may compare against that with  
`[s.f.name for s in sys.states]`. It appears to be the same index given in `sol(t)`

---

<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: [July 21, 2021, 1:14am UTC](https://discourse.julialang.org/t/modelingtoolkit-how-to-get-variable-index-of-ode-solution-as-interpolating-function/64999/2 "2021-07-21T01:14:40Z")

</div>

`sol(1.2,idxs=x)`

---

<div class="post-metadata">

### Author: ![Egwene\_al\_Vere](https://avatars.discourse-cdn.com/v4/letter/e/df788c/32.png) [@Egwene\_al\_Vere](https://discourse.julialang.org/u/Egwene_al_Vere)
#### Post date: [July 21, 2021, 1:16am UTC](https://discourse.julialang.org/t/modelingtoolkit-how-to-get-variable-index-of-ode-solution-as-interpolating-function/64999/3 "2021-07-21T01:16:39Z")

</div>

thanks!
