Hi all,

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 
<https://gist.github.com/Poofjunior/d574c789b882f54dfe71885408e45715>:
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 [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/e7f82a35-09bf-45f7-b540-4ed07738c5b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to