If there is no particular reason that you prefer to use strings, you
should explicitly create these symbols.
x, y, z = symbols('x y z')
If you work on the console for interactive stuff and do not write
library code you can use the following faster and sloppier command
var('x y z') # x, y and z will go automatically in the global namespace
If you need to use strings (e.g. parsing some input on a webpage) you
can use the .free_symbols property
expression = sympify('user_string')
set_of_symbols = expression.free_symbols # no default order
On 30 June 2012 10:52, Daniel Farrell <[email protected]> wrote:
> Dear list,
>
> I use the sympify function to return an symbolic expression of the string
> and then call the jacobian function. However, I need to extract the
> variables that were created when the string was processed by sympify?
>
> For example, the Jacobian of a quadratic equation is,
>
> import sympy
> equation = sympy.sympify( " a * x**2 + b * x + c ")
> X = sympy.Matrix([equation])
> Y = sympy.Matrix([a,b,c]) # here, not general because must be manually
> specified
> jacobian = X.jacobian(Y)
>
> Everything is general apart from the Y = sympy.Matrix([a,b,c]) line.
>
> Is there a away to extract the variables added (a, b, c) to the namespace by
> the sympify function? If so this code an be used to calculate the Jacobian
> of any function.
>
> Best wishes,
>
> Dan
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "sympy" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/sympy/-/GD8TJ1nDeSsJ.
> 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.
--
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.