28 May 21:36 2016

### Render an Expression containing Python variables without symplifying or evaluating it.

Hi all,

9.8⋅10

Or.. something more complicated:

constants = {"lbs_per_bucket": 4, "lbs": 2, "lbs_friend": 3}render_expression("(lbs/lbs_per_bucket + lbs_friend)**2", constants)

2 ⎛2 ⎞ ⎜─ + 3⎟ ⎝4 ⎠

Is there a built-in sympy way of rendering an expression that contains python variables without evaluating it?

On the flip-side, is there a way of defining a multi-variable expression, like x + 2y and then inputting the value of y such that sympy just solves for x? In that sense I could include variables from python take take on the defined symbol values.

Cheers--and thanks for taking a look!

-- Often in Python, I'll punch in an equation based on constants like this:

mass = 10

acceleration = 9.8

print(mass * acceleration)

I'd love to be able to use Sympy to find/replace these variables in an expression and then print the unicode result. For me I'd appreciate being able to see the nicely rendered expression to make sure I typed it in correctly.

I've written a snippet that does just that:

vars_dict = {"mass":10,

"acceleration": 9.8}

render_expression("mass * acceleration", vars_dict)

where the output looks like the following:

9.8⋅10

Or.. something more complicated:

constants = {"lbs_per_bucket": 4, "lbs": 2, "lbs_friend": 3}render_expression("(lbs/lbs_per_bucket + lbs_friend)**2", constants)

2 ⎛2 ⎞ ⎜─ + 3⎟ ⎝4 ⎠

Is there a built-in sympy way of rendering an expression that contains python variables without evaluating it?

On the flip-side, is there a way of defining a multi-variable expression, like x + 2y and then inputting the value of y such that sympy just solves for x? In that sense I could include variables from python take take on the defined symbol values.

Cheers--and thanks for taking a look!

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 sympy+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.

To post to this group, send email to sympy-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.

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/e7f82a35-09bf-45f7-b540-4ed07738c5b0%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.