How to programmatically create symbolic variable names in Symbolics.jl

Essentially, I am looping over indices and I need to use those indices to create symbolic variable names.

A simplified version of what I am trying to do as shown using SymPy:

for i=1:5
   for j=2:7

In actuality, the indices are all coming from a list so it is not straightforward to program using for loops.

The only method for defining symbolic variables I can find for Symbolics.jl is

@variables x1

Does anyone have suggestions for how I can incorporate the x$i symbolic variable construction in Symbolics? Thank you.

@variables $x

Can you elaborate? Is x supposed to be assigned as something beforehand?

yes it’s interpolating in a name.

I’ve tried different formulations but can’t seem to figure out what the requirements on x are. Can you show an example of how x is defined before @variables $x?

x = :myvar

I have struggled to add a time dependency in this way. Is this supported?

julia> @variables t x(t)
2-element Vector{Num}:

julia> ẋ = Symbol(:Δ, Symbol(Symbolics.value(x)))

julia> @variables $ẋ
1-element Vector{Num}:

julia> Δx
ERROR: UndefVarError: `Δx` not defined

I can accomplish this by leaving out the time dependency, and adding it back later…

julia> ẋ = :Δx

julia> @eval @variables $(ẋ)(t)
1-element Vector{Num}:

julia> Δx

Oh, that’s not intended. Open an issue.