On Jul 18, 5:44 pm, Aaron Meurer <[email protected]> wrote:
> SymPy is built on top of Python, so symbol names have to be defined to
> be used.
>
> x = Symbol('x') is no different (from Python's point of view) from x =
> 1 or x = 'x'.  It is just a variable assignment.  In particular, this
> means that variable names don't have to match at all the name of the
> Symbol that they hold.  Nowhere can anything tell what the name of
> your variable is, or if you even used one at all (e.g., it's
> impossible for a function like solve() to tell if you used x =
> Symbol('x'); solve(x**2 - 1) or just solve(Symbol('x')**2 - 1) or even
> y = Symbol('x'); solve(y**2 - 1); they all appear exactly the same to
> it).
>
> I don't know if this helps you in your application.  It's really hard
> to say what you should do without knowing more.
>
> Finally, I should point out that if you are working strictly
> interactively, there is the var() function, which performs some magic
> to define symbols for you, like
>
> >>> var('x y z')
> >>> x
>
> x
>
> However, it's not recommended to use this function unless you are
> working interactively, because there can be some subtle issues (e.g.,
> it might not work unless it's called at the module level), and it's
> somewhat bad style.
>
> Another option would be to create the variable definitions
> programitically.  The python() function might help.  For example:
>
> In [67]: python(symbols("x, y, z, a, b, c, d"))
> Out[67]:
>      x = Symbol('x')
>      y = Symbol('y')
>      z = Symbol('z')
>      a = Symbol('a')
>      b = Symbol('b')
>      c = Symbol('c')
>      d = Symbol('d')
> e = (x, y, z, a, b, c, d)
>
> You can take all those definitions and paste them into your file.
>
> Aaron Meurer
>
>


Thank you for the reply.

The following is ugly (and perhaps dangerous), but seems to work:

-----

import sympy as sp

vars = ['mx1','mx2','mx3']

for v in vars:
    exec("%s=sp.Symbol('%s')" % (v,v))

print sp.expand((mx1*mx2 + mx3)**2)

-----

Best regards,
Brad

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sympy?hl=en.

Reply via email to