开发者

Numerical integration of a function known only through data points - AS3 Preferred

开发者 https://www.devze.com 2023-04-12 17:02 出处:网络
Is there any library or open source function that approximate the area under a line that is described by some of its values taken at irregular intervals?

Is there any library or open source function that approximate the area under a line that is described by some of its values taken at irregular intervals?

Action Script would be preferred but J开发者_如何学编程ava might work fine as well.


You could use the as3mathlib math library. Here's the relevant class:

http://code.google.com/p/as3mathlib/source/browse/trunk/src/com/vizsage/as3mathlib/math/calc/Integral.as

It includes the most common integral approximation methods.

Edit for more explanation (based on comments below):

Use timestamp values for each date; only convert to anything else if you need to display it to the user, and do so at the very end.

Hopefully there's a standard greatest common divisor (GCD) among the various differences between each set of adjacent timestamps. (If not, you'll need to calculate that first.) In other words, hopefully each timestamp differs by a number of whole days. If so, the GCD is 1 day. If it's not like this, you'll have to calculate what that GCD equals on the fly.

Then, use the GCD value in combination with the delta between the first and last timestamps to determine n, the number of partitions. Then, in f (your function to be integrated), determine whether the passed x corresponds to a defined timestamp. If so, return the numeric_value associated with that timestamp. If not, interpolate between the numeric_values of the nearest two defined timestamps, and return that.

0

精彩评论

暂无评论...
验证码 换一张
取 消