# Evaluating arbitrary symbolic expression on ODE solution

**URL:** <https://discourse.julialang.org/t/evaluating-arbitrary-symbolic-expression-on-ode-solution/136130>\
**Category:** Modelling & Simulations\
**Tags:** modelingtoolkit\
**Created:** [March 11, 2026, 6:22am UTC](https://discourse.julialang.org/t/evaluating-arbitrary-symbolic-expression-on-ode-solution/136130 "2026-03-11T06:22:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [March 11, 2026, 6:22am UTC](https://discourse.julialang.org/t/evaluating-arbitrary-symbolic-expression-on-ode-solution/136130/1 "2026-03-11T06:22:09Z")

</div>

If I have an `ODESolution`, I can evaluate some variable at some `t=5` with `sol(5, idxs=sys.some_variable)`, but what if I have `EvalAt(15)(sys.some_variable) - EvalAt(10)(sys.other_variable)`. This is a reasonable expression to evaluate on the solution. But `sol(10, idxs=...)` does not work, neither does `sol[...]`. How should I do it?

I looked into [Function Building and Compilation (build\_function) · Symbolics.jl](https://docs.sciml.ai/Symbolics/stable/manual/build_function/), but it’s not obvious how to put that into practice.

---

<div class="post-metadata">

**Author:** ![baggepinnen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/baggepinnen/32/693_2.png) [@baggepinnen](https://discourse.julialang.org/u/baggepinnen)\
**Post date:** [March 11, 2026, 9:09am UTC](https://discourse.julialang.org/t/evaluating-arbitrary-symbolic-expression-on-ode-solution/136130/2 "2026-03-11T09:09:45Z")

</div>

It’s not quite clear to me what you want to do, why do you need the `EvalAt`? Does

```julia-auto
sol(15, idxs=sys.some_variable) - sol(10, idxs=sys.other_variable)

```

not work?

---

<div class="post-metadata">

**Author:** ![cstjean](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cstjean/32/1444_2.png) [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Post date:** [March 11, 2026, 9:23am UTC](https://discourse.julialang.org/t/evaluating-arbitrary-symbolic-expression-on-ode-solution/136130/3 "2026-03-11T09:23:56Z")

</div>

Well, yes it does. However, I am letting my users specify constraints (in an optimization problem) as symbolic expressions (or well, I _would like to do that_), and thus I need to evaluate that symbolic expression on the solution. I don’t know how to do that.

Maybe there’s a better way (or alternative package) to do the optimization? Apparently, once upon a time

```julia
@optimization_model model begin
      @constraints begin
          EvalAt(0.5)(x) ~ 2.0 # x must equal 2.0 at t=0.5
      end
  end

```

was a thing, but I don’t know what became of it.
