On 1/14/08, Jason Grout <[EMAIL PROTECTED]> wrote: > > John Cremona wrote: > > The problem is surely that the pieces f1a etc are just Python > > lambda-functions, yet the integral() method is being called on each of > > these in the line > > return sum([funcs[i].integral(x,invs[i][0],invs[i][1]) for i in range(n)]) > > so the problem arises since you are asking to integrate each funcs[i] > > but they do not know how to integrate themselves. > > > > The solution would be to define your f1a (etc) not as lambda-functions > > but as functions which Sage knows how to integrate, and then form the > > piecewise function out of those "integrable" components. > > > > Something like this? > > sage: f1a(x)=(-x+1) > sage: f1b(x)=x+1 > sage: f2a(x)=(-(x-2)-1) > sage: f2b(x)=(x-2)-1 > sage: tri_wave = piecewise([ [(-1,0), f1a], [(0,1),f1b], \ > [(1,2),f2a],[(2,3),f2b]]) > sage: tri_wave.integral() > 2 > > > I noticed that the following gives an error in Sage 2.9: > > sage: f(x)=-x > ------------------------------------------------------------ > File "<ipython console>", line 1 > <type 'exceptions.SyntaxError'>: can't assign to function call (<ipython > console>, line 1) > > Is that a bug? It seems to be related to the negative sign, since the > following works: > > sage: f(x)=(-x) > sage: f(2) > -2
Was there something funny about your x in the above example, because it works fine for me: teragon:standard was$ sage ---------------------------------------------------------------------- | SAGE Version 2.9.3, Release Date: 2008-01-05 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- sage: f(x) = -x sage: f(2) -2 --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://sage.math.washington.edu/sage/ and http://sage.scipy.org/sage/ -~----------~----~----~----~------~----~------~--~---