1

I'm trying to find a way to calculate area under a curve using python 2.7 when the function is unknown. Only data I have are coordinates, such as:

0       0
0.000194439     0
0.000388878     0
0.000583317     0
0.000777756     0
0.000972195     0
0.00116663      0
0.00136107      0
0.00155551      0
0.00174995      0
0.00194439      0
0.00213883      0
0.00233327      0
0.00233327      0.00588235
0.00252771      0.00588235 
...............................
.................................

Complete data.

The values will always be positive. More often than not the function will resemble a logarithmic one, but that is not guaranteed.

I could calculate (x2-x1)*y and so on for an approximation, but I'd prefer using integration.

Thus my question is:
How could I find out the function for given coordinates reliably in code? Or is it possible to accomplish this without one? Asking the latter merely to cover all bases, since my math is extremely rusty

4

1 回答 1

5

How could I find out the function for given coordinates reliably in code?

You can't. Given a set of points, there are an infinite number of functions that go through all of those points. One of them can be constructed using a polynomial of degree up to N (where N is the number of data points that you have). However, this is function almost never matches the reality you're trying to represent (It usually ends up oscillating wildly between data points). In general, the best you can do is is to create some sort of approximation of the integral.

The approximation you've described isn't too bad on most functions as long as your sampling rate is adequate, although you could do a little better using the trapeziodal rule or Simpson's Rule.

于 2013-06-17T12:34:22.803 回答