Time for a paradigm shift. Dah-da-da-daahh! (Imagine Jeff Dunham’s “Melvin, the Superhero Guy”)
First, a window to play with.
Integral_2014-11-07_1314.proj (41.8 KB)
Ok, the best you’ll be able to do is an approximation. The only thing we have are a set of discrete data points. Strictly speaking, we have no idea what is happening between the points. Graphing these points will give us a straight line between each one. The more samples you have the finer the details, and the closer the approximation to a curve it will be, but it’s still a bunch of straight lines.
Here’s a random dataset:
And the area we want to find:
Now, let’s zoom in on a section. If you break each area between points, you can see that each one is a trapezoid. So, adding up all the trapezoids will give the area under the “curve”
Here’s the script placed inside the Property change event in Table 1. (Not optimized for anything except illustrating the process )
dataIn=system.dataset.toPyDataSet(event.source.parent.getComponent('Table').data)
headers=["x","y"]
data=[]
x=0
for row in dataIn:
# print x, row[2]
x+=1
data.append([x,row[2]])
event.source.parent.getComponent('Chart').Data=system.dataset.toDataSet(headers,data)
event.source.parent.getComponent('Table 1').data=system.dataset.toDataSet(headers,data) # The Visually friendly Table...
runningSum=0
for point in range(len(data)-1):
b1 = float(data[point][1])
b2 = float(data[point+1][1])
h = float(data[point+1][0])-float(data[point][0])
sectionArea=(b1+b2)/2*h
runningSum+=sectionArea
print b1,b2,sectionArea, runningSum
event.source.parent.getComponent('Numeric Label').value=runningSum