On Thu, 11 Feb 2021 at 11:19, Thomas Ligon <[email protected]> wrote:
>
> "The solution to this in Python is to use lists or tuples or some other 
> container rather than raw variables. For example:
>
> x = symbols('x:10')"
>
> Based on that, and
> Core — SymPy 1.7.1 documentation
>
> a = symbols('a:2*maxIter+1')
>
> The result is
>
>  (a0*maxIter+1, a1*maxIter+1)
>
> The problem is that symbols does not support variables after the colon, 
> defeating the whole purpose of using indexed symbols to begin with.

You can use the features of the Python language to generate the string
as input to the symbols function:

>>> num_symbols = 10

This is using %-formatting of strings:

>>> 'x:%d' % num_symbols
'x:10'
>>> symbols('x:%d' % num_symbols)
(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)

This is using f-strings:

>>> f'x:{num_symbols}'
'x:10'
>>> symbols(f'x:{num_symbols}')
(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9)

> I am trying to use indexed symbols.

Note that "indexed symbols" means something different in sympy e.g.:

>>> from sympy import IndexedBase
>>> x = IndexedBase('x')
>>> x
x
>>> x[0]
x[0]

IndexedBase represents a mathematical quantity that can be subscripted
but in a symbolic way. For example if I have some data points that I
refer to as x_1, x_2, etc. and I want to refer to x_i then I can use
IndexedBase and index it with a symbol.

Oscar

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxRCL%3D2cQKoGTJjUos6onXEWAujitgDwZaY3Ohhn2ONmvA%40mail.gmail.com.

Reply via email to