It shouldn't be too hard to implement, though, I would imagine. One just needs to implement _print_Sum on the various code printers. lambdify() might be trickier because the code has to fit in a lambda expression. I'm not really sure what the best way to make it work there would be.
Aaron Meurer On Fri, Jan 31, 2014 at 9:25 AM, Federico Vaggi <vaggi.feder...@gmail.com> wrote: > Yeah - the problem seems to be that SymPy doesn't know how to convert Sum > into a Python function - or at least complains about it. > > > On Friday, 31 January 2014 15:54:32 UTC+1, Jason Moore wrote: >> >> Ideally, a code printer that printed a python function for this expression >> would automatically create the numpy code you show from the expression. But, >> I'm not sure any of the current printing facilities in sympy can do that. I >> tried lamdify, ccode, and codegen with no luck. >> >> >> Jason >> moorepants.info >> +01 530-601-9791 >> >> >> On Fri, Jan 31, 2014 at 3:45 AM, Federico Vaggi <vaggi.f...@gmail.com> >> wrote: >>> >>> Hi everyone, >>> >>> I was using SymPy to derive an analytic expression for a Jacobian matrix >>> in a least squares system. It worked very well, and I simplified the system >>> down to an equation which is very easy to evaluate, which however involves a >>> vector of residuals: >>> >>> The final SymPy expression is this: >>> >>> Sum((-10.0*exp(-0.1*t) + 10.0)*d, (t, 1, 50)) >>> >>> >>> Where t is a variable, and d is an indexed base. How can I numerically >>> replace d with a vector containing 50 residuals, and actually compute the >>> sum? It would be trivial to code this up in numpy using a loop, but since I >>> was preparing an iPython notebook, I thought it would be nice to do as much >>> as possible within SymPy. >>> >>> >>> >>> >>> The equivalent numpy code would be this: >>> >>> >>> >>> >>> tot = 0.0 >>> >>> for t in range(50): >>> >>> tot += (-10*np.exp(-0.1*t) + 10)*d[t] >>> >>> >>> >>> >>> >>> >>> >>> -- >>> 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+un...@googlegroups.com. >>> To post to this group, send email to sy...@googlegroups.com. >>> >>> Visit this group at http://groups.google.com/group/sympy. >>> For more options, visit https://groups.google.com/groups/opt_out. >> >> > -- > 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+unsubscr...@googlegroups.com. > To post to this group, send email to sympy@googlegroups.com. > Visit this group at http://groups.google.com/group/sympy. > For more options, visit https://groups.google.com/groups/opt_out. -- 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+unsubscr...@googlegroups.com. To post to this group, send email to sympy@googlegroups.com. Visit this group at http://groups.google.com/group/sympy. For more options, visit https://groups.google.com/groups/opt_out.