I would consider this to be a bug. You should open an issue for it. If you use Idx as Francesco suggests, there is a different error
ValueError: lhs indices must match non-dummy rhs indices in sin(u[k]) + u0[k] which also looks like a bug. Aaron Meurer On Thu, Apr 14, 2016 at 2:59 AM, Nico Schlömer <[email protected]> wrote: > From an object like `sin(u[k]) + u0[k]` I would like to get the > corresponding C code as a string. Since `k` is a variable, I cannot use > `MatrixSymbol`, but there's always `IndexedBase` of course. With > ``` > u = IndexedBase('u') > u0 = IndexedBase('u0') > k = Symbol('k') > y = sin(u[k]) + u0[k] > ``` > things are looking good, but then > ``` > from sympy.utilities.codegen import codegen > [(c_name, c_code), (h_name, c_header)] = codegen(("f", y), "C") > ``` > tells you > ``` > sympy.tensor.indexed.IndexException: > Range is not defined for all indices in: u[k] > ``` > I could perhaps go through all `IndexedBase` instances in `y` and > `.subs`titute them with a variable with the string `u[k]`, but that feels > hackish. > > Any hints? > > -- > 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 post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/sympy. > To view this discussion on the web visit > https://groups.google.com/d/msgid/sympy/61a4dd23-0b06-4559-9da8-10f666464fc5%40googlegroups.com. > For more options, visit https://groups.google.com/d/optout. -- 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 post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/sympy. To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6%2BNOYU7QYMsHpg7oK409sx11mC_%2Bd3WLmhHbsOq4f5mVQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
