Hi Matt,
On Sun, Jan 11, 2009 at 11:18 AM, Matt Ball <[email protected]> wrote:
> Hi,
> I'm currently using Sympy in a small Python script to take a user input
Thanks for your interest.
> function from the command line and turn it into Python lambda, like this:
> print "Enter f in ∇²u = f (0 for Laplace case). f is a 2D equation in terms
> of x and y."
^^^ That's a cool unicode for \nabla. We should add it to sympy pretty
printing when we implement div/grad and similar operators soon. I'll
be needing it soon.
> f = simplify(raw_input("f = "))
Shouldn't this by sympify()? Simplify() makes the input expression
simpler as well (maybe you want this).
> symbols = f.atoms(Symbol)
> x = Symbol("x")
> y = Symbol("y")
> ...
>
> return lambdify((x,y),f.subs({'x':x,'y':y}),"math")
what is the meaning of f.subs({'x':x,'y':y}) here? It seems to me the
above line is equivalent to this:
return lambdify((x,y), f, "math")
or am I missing something?
At least in theory, it doesn't matter which particular instances of
the Symbol() class you use, if it does, it's a bug.
>
> Is there a way to easily, automatically replace reasonable constants, such
> as e and pi, with their actual value in the python lambda? Right now,
Why not to use .subs({pi: 3.14, E: 2.72})?
> anything that isn't a number is just a symbol, and I would rather not have
> to have a long-ish dictionary in each lambdify.
By the "long-ish" dictionary, do you mean this dict: {pi: 3.14, E:
2.72}? (of course when you add all the constants in there, it will
get longer)
You can convert constants using .evalf(), so maybe we can write some
function, that does that for all constants automatically.
> Likewise, is there an easy way to automatically enable
> recognition/functionality of all the functions that Sympy can handle? I
Just use sympify:
In [1]: sympify("factorial(x)+sin(y)")
Out[1]: Γ(1 + x) + sin(y)
> tried playing around with mpmath, but that failed on even simple cases, such
> as factorial(x), where the factorial function itself is recognized, but
> later on when evaluating that function at a given point, I get a NameError:
> global name 'gamma' is not defined issue (I imagine it has something to do
> with using the gamma function to evaluate a factorial for non-natural
> numbers). Thanks for the help again!
Please post here the exact commands you tried --- I am not sure what
went wrong from your description.
But for the above things imho what you need is just sympify().
Ondrej
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---