On 04/28/2010 07:21 PM, janwillem wrote:
> I have a function of a few variables that is the result of some
> symbolic manipulations like differentiation and matrix operations. I
> would like to do some Monte Carlo work on this to get the distribution
> of the function result as a function of the distributions of the
> inputs. However, the subs method (like /. in Mathematica) is much to
> slow. Is there an elegant solution for that?
> What came to my mind is writing the result to a file and then
> importing that like for a more trivial case:
>
> X, F, B = sympy.symbols('XFB')
> Y = X/F - B
> f = open('sympy_function.py' ,'w')
> f.write('def fsympy(X,F,B):\n')
> f.write('    return %s\n' % Y)
> f.close()
> from sympy_function import *
>
> With numerical values for x, f and b:
> y = fsympy(x, f, b) is 300 times faster than y = Y.subs({X:x, F:f,
> B:b}) and only 10% slower than straightaway y = x/f -b
>
> So that works but I do not consider it elegant. Something better?
>
>   
Take a look into lambdify - it basically does what you proposed without
doing the file manipulation ;)

Sebastian

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

Reply via email to