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<javascript:> > > 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 <javascript:>. >> To post to this group, send email to sy...@googlegroups.com <javascript:> >> . >> 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.