pluie
April 1, 2023, 2:15pm
1
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:
vars=[]
for i=1:5
for j=2:7
push!(vars,symbols("x$i$j"))
end
end
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.
pluie
April 1, 2023, 4:58pm
3
Can you elaborate? Is x supposed to be assigned as something beforehand?
yes it’s interpolating in a name.
pluie
April 1, 2023, 6:33pm
5
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
?
cadojo
December 26, 2023, 4:39pm
7
I have struggled to add a time dependency in this way. Is this supported?
julia> @variables t x(t)
2-element Vector{Num}:
t
x(t)
julia> ẋ = Symbol(:Δ, Symbol(Symbolics.value(x)))
Symbol("Δx(t)")
julia> @variables $ẋ
1-element Vector{Num}:
var"Δx(t)"
julia> Δx
ERROR: UndefVarError: `Δx` not defined
I can accomplish this by leaving out the time dependency, and adding it back later…
julia> ẋ = :Δx
:Δx
julia> @eval @variables $(ẋ)(t)
1-element Vector{Num}:
Δx(t)
julia> Δx
Δx(t)
Oh, that’s not intended. Open an issue.