Iif your points are (x_0,y_0), (x_1,y_1),...,(x_n,y_n), don't you just take the sum of the (x_{i+1}-x_i)*(y_{y+1}-y_i)/2 ? That's a one-liner.
sage: pts = [ (0, 0), (1, 3), (2, 8)] sage: area = sum([(pts[i+1][0]-pts[i][0])*(pts[i+1][1]-pts[i][1])/2 for i in range(2)]) sage: area 4 On Thu, Apr 9, 2009 at 8:53 AM, hpon <peter.norli...@gmail.com> wrote: > > > Hi, > > I'm reading data points from a graph. The points could for example be > (0, 0), (1, 3), (2, 8). I would like to calculate the integral of the > piecewise linear segments that these points span. > > Ideally, I want a command of this type: integral( (0, 0), (1, 3), (2, > 8) ). Does such a command exist in Sage? > > I found trapezoid_integral_approximation, for instance, but this one > is messy compared to what I want. Here you need to define the > interval and local function for each segment, instead of just listing > the points. > > Below is an attempt to use trapezoid_integral_approximation in the > fashion I desire. It's bulky and does not work. > > y_0, s_0, y_1, s_1, y = var('y_0, s_0, y_1, s_1, y'); > > f (y_0, s_0, y_1, s_1, y)= (y - y_0) * ((s_1 - s_0) / (y_1 - y_0)) + > s_0; > > sigma = Piecewise([[ (0, 1), f (0, 100, 1, 300) ]]); > print f.trapezoid_integral_approximation(4); > > Regards, > hpon > > > --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---