JuliaSymbolics / Symbolics.jl

Symbolic programming for the next generation of numerical software
https://symbolics.juliasymbolics.org/stable/
Other
1.31k stars 146 forks source link

How to define a long symbolic vector using for loop with Symbolics.jl #767

Open xiang-yu opened 1 year ago

xiang-yu commented 1 year ago

How to define a symbolic vector using for loop with Symbolics.jl? For example, x=[x1, x2, x3, x4, …, x100], where xi are all variables defined using @variables. It can be easily done using sympy.jl as julia> N=100, x = [symbols(“x$i”) for i in 1:N].

For short vector, x = @variables x1, x2, x3 work. However for, 100 or even 1000 long vectors, a for loop would be useful.

Please note that I must use Symbolics.jl for the sake of speed and complicated matrix manipulation. I am aware of the symbolic arrays introduced at Symbolic arrays · Symbolics.jl 1, but it does not work for my purpose.

bowenszhu commented 1 year ago

See https://github.com/JuliaSymbolics/Symbolics.jl/issues/694#issuecomment-1209842450

xiang-yu commented 1 year ago

Thank you. x = Symbolics.variables(:x, 1:N) works well. Any chance these functions can be added in the manual https://symbolics.juliasymbolics.org/dev/ or Symbolics wiki so that they can be easily searchable?