# How to make ODESystem with DataInterpolations latex output more readable?

**URL:** https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700
**Category:** Modelling & Simulations
**Tags:** question
**Created:** [September 29, 2024, 11:19pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700 "2024-09-29T23:19:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)
#### Post date: [September 29, 2024, 11:19pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/1 "2024-09-29T23:19:47Z")

</div>

I have defined my model in ModelingToolkit.jl as such:

```julia
# define model parameters
@parameters Ci Ria Aw

# define sub-model components
@named C_i = Capacitor(C=Ci) # thermal capacity of interior
@named R_ia = Resistor(R=Ria) # thermal resistance between interior and ambient
@named T_a = Voltage() # ambient temperature
@named P_h = Current() # thermal power in kW 
@named P_s = Current() # solar power in kW
@named A_w = Gain(k=Aw) # dimensionless window area gain (SHGC*Area)
@named gnd = Ground() # ground node

# input functions
@named T_a_f = TimeVaryingFunction(input_funcs[:T_a])
@named P_h_f = TimeVaryingFunction(input_funcs[:P_h])
@named P_s_f = TimeVaryingFunction(input_funcs[:P_s])

# collect all components in a vector
components = [C_i, R_ia, T_a, P_h, P_s, A_w, T_a_f, P_h_f, P_s_f, gnd]

# make component connections
conn = [
    connect(C_i.p, R_ia.p),
    connect(R_ia.n, T_a.p),
    connect(C_i.n, gnd.g),

    # ambient temperature input
    connect(T_a.p, R_ia.n),
    connect(T_a.V, T_a_f.output),
    connect(T_a.n, gnd.g),

    # solar power input: A_w * P_s
    connect(A_w.output, P_s.I),
    connect(A_w.input, P_s_f.output),
    connect(P_s.n, C_i.p),
    connect(P_s.p, gnd.g),

    # thermal power input
    connect(P_h.n, C_i.n),
    connect(P_h.I, P_h_f.output),
    connect(P_h.p, gnd.g)
]

```

The input functions are given by DataInterpolations.jl:

```julia
# define interpolated input functions of sampled data
T_a_interp = AkimaInterpolation(df.T_a, df.t_hour)
P_s_interp = AkimaInterpolation(df.P_s, df.t_hour)
P_h_interp = AkimaInterpolation(df.P_h, df.t_hour)

input_funcs = Dict(:T_a => T_a_interp, :P_s => P_s_interp, :P_h => P_h_interp)

```

Now when I display the equations of this model (after calling `structural_simplify(sys)` I get the following LaTeX output, which is not very readable:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/b/e/be4a6dcc3bfcd41364fef1a80249306ab2fc9ae7.png)

I would like this more readable so I can inspect the equations.

Related question: can I make outputs / inputs such as C\_{i\_+ v}(t) display something else as well which makes more sense to me? For example, change C\_{i\_+ v}(t) to V\_{C}(t).

ps. I am on ModelingToolkit v8.75 due to requirements of a package I am using.

Thanks a lot 🙂

---

<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: [September 29, 2024, 11:25pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/2 "2024-09-29T23:25:18Z")

</div>

This is changed a bit in ModelingToolkit v9. With the latest versions, you can have a parameter that is a callable function. This is much better because you can see here that every `f` call constructs the interpolation and then calls it, while the parameter form will cache it and then reuse it. So the v9 form both makes the printout simpler (just a p(t)) and improves the performance.

That said, you can somewhat simulate it on v8 by building a function with the interpolation enclosed and then registering the enclosed function.

---

<div class="post-metadata">

### Author: ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)
#### Post date: [September 29, 2024, 11:28pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/3 "2024-09-29T23:28:50Z")

</div>

Ah okay great. By registering do you mean as it’s done in this post from a while back? [Interpolation within ModelingToolkit framework - #6 by jairorua](https://discourse.julialang.org/t/interpolation-within-modelingtoolkit-framework/59432/6)

---

<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: [September 29, 2024, 11:35pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/4 "2024-09-29T23:35:06Z")

</div>

Kind of, that’s not the enclosed form and will allocate the vectors, though that form will still work.

---

<div class="post-metadata">

### Author: ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)
#### Post date: [September 29, 2024, 11:42pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/5 "2024-09-29T23:42:11Z")

</div>

I see. By enclosed do you mean:

```julia
@register f_interpolate(t)

```

instead of:

```julia
@register f_interpolate(t, table_t::AbstractVector, table_u::AbstractVector)

```

Where the data has already been defined in `f_interpolate(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: [September 29, 2024, 11:43pm UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/6 "2024-09-29T23:43:22Z")

</div>

Yes exactly.

---

<div class="post-metadata">

### Author: ![langestefan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/langestefan/32/207923_2.png) [@langestefan](https://discourse.julialang.org/u/langestefan)
#### Post date: [September 30, 2024, 12:20am UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/7 "2024-09-30T00:20:09Z")

</div>

I must still not be doing something right then, this leads to the same result as before:

```julia
    # time variable 
    @variables t

    # define interpolated input functions of sampled data
    function T_a(t)
        y = df.T_a
        x = df.t_hour
        int = AkimaInterpolation(y, x)
        out = int(t)
    end

    function P_s(t)
        y = df.P_s
        x = df.t_hour
        int = AkimaInterpolation(y, x)
        out = int(t)
    end

    function P_h(t)
        y = df.P_h
        x = df.t_hour
        int = AkimaInterpolation(y, x)
        out = int(t)
    end

    @eval @register_symbolic P_h(t)
    @eval @register_symbolic P_s(t)
    @eval @register_symbolic T_a(t)

    input_funcs = Dict(:T_a => T_a, :P_s => P_s, :P_h => P_h)

```

---

<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: [September 30, 2024, 9:57am UTC](https://discourse.julialang.org/t/how-to-make-odesystem-with-datainterpolations-latex-output-more-readable/120700/8 "2024-09-30T09:57:03Z")

</div>

You can’t eval it if it’s in a function since that would be in the wrong world age
