# Using Tuples within ModelingToolkit.jl?

**URL:** <https://discourse.julialang.org/t/using-tuples-within-modelingtoolkit-jl/99350>\
**Category:** General Usage\
**Tags:** modelingtoolkit\
**Created:** [May 24, 2023, 8:32pm UTC](https://discourse.julialang.org/t/using-tuples-within-modelingtoolkit-jl/99350 "2023-05-24T20:32:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarkIlg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/markilg/32/28109_2.png) [@MarkIlg](https://discourse.julialang.org/u/MarkIlg)\
**Post date:** [May 24, 2023, 8:32pm UTC](https://discourse.julialang.org/t/using-tuples-within-modelingtoolkit-jl/99350/1 "2023-05-24T20:32:59Z")

</div>

Trying to utlized MTK on a larger simulation and having trouble with functions that return tuples that are a function of state. For example:

```julia
function foo(x)
    return 1.0,2.0
end
@register_symbolic foo(x)

function plant(; name)
    @variables x(t)=1 u(t)=0 y(t)=0
    D = Differential(t)

    k1,k2 = foo(x); 

    eqs = [D(x) ~ -x*k1 + u;
              y ~ x*k2]
    ODESystem(eqs, t; name = name)
end

@named p = plant()

```

and receiving the error:

> ERROR: BoundsError: attempt to access Num at index [2]

I realize this is a trivial example but demonstrates the point. In my actual implementation, the functions that rely on states are complex and have external dependencies (external c-library). I’ve tried writing simple wrappers but at a loss. How do we handle such cases?

---

<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 25, 2023, 1:01pm UTC](https://discourse.julialang.org/t/using-tuples-within-modelingtoolkit-jl/99350/2 "2023-05-25T13:01:16Z")

</div>

I’m not sure it can handle tuple outputs in registered functions. That’s worth an issue. It would need to treat it internally as an array variable.
