插入数组(或两个) [英] Interpolation over an array (or two)

查看:141
本文介绍了插入数组(或两个)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个java库或一些帮助来编写我自己的插值函数。那是我有两个双重阵列,这两个阵列是潜在的不同大小,但是是有序的。我需要能够估计中间值,并插入两个数组变成相同的大小。事实上,插值中出现的总点数是2个数组大小减去1的总和。每个数组的范围必须保持不变,因此不需要外推。



例如a1 = [1,4,9,16,25,36]和a2 = [6,9,14,30]



结果可以是例如<

a1 = [1,2.25,4,6.25,9,12.25,16,25,36]

a2 = [6,6.5625,这些例子是 f(x)= x ^ 2和g(x(x)) )= x ^ 2 + 5 ,但是可以很容易地是任何多项式 - 点是能够从数据集中估计/近似函数,足以提供足够的插值。这里x值只是输入数组的索引。在输出中只有y值很重要。

解决方案

其他答案给你线性插值 - 用于复杂的非线性数据。 我想要一个样条拟合,(样条插值)我相信。



样条拟合使用数据中的一组控制点描述数据区域,然后在控制点之间应用多项式插值。更多的控制点为您提供更准确的配合,更少一般更适合。样条线比线性拟合精度要高于普通回归拟合,比使用高阶多项式更快,因为它不会在控制点之间发生疯狂的事情。



<我不记得我头上的名字,但是在Java中有一些非常适合的库 - 我建议你寻找一个而不是编写你自己的功能。






**编辑:可能有用的库:**





**可能有用的理论/代码:**




  • 带代码的样条applet:链接

  • Arkan 多线条到贝塞尔样条的样条拟合

  • 理论的样条,以及一些数学拟合。更多的数学,较少的代码,可能会有帮助,如果图书馆没有。


I'm looking for a java library or some help to write my own interpolation function. That is I have two arrays of doubles which are potentially different sizes, but are ordered. I need to be able to make an estimate of intermediate values, and insert so that both arrays become the same size. In fact the total number of points appearing in the interpolation is the sum of the 2 array sizes minus 1. The range of each array must stay the same however, so there is no extrapolation needed.

eg. a1 = [1, 4, 9, 16, 25, 36] and a2 = [6, 9, 14, 30]

the results could be eg.

a1 = [1, 2.25, 4, 6.25, 9, 12.25, 16, 25, 36] and a2 = [6, 6.5625, 7.25, 9, 10.0625, 11.25, 14, 25.25, 30]

these examples are f(x) = x^2 and g(x) = x^2 + 5, however could easily have been any polynomial - the point is to be able to estimate/approximate the function from the dataset well enough to provide decent enough interpolation. Here the x value is just the index of the input array. In the output only the y values are important.

解决方案

The other answers give you linear interpolations -- these don't really work for complex, nonlinear data. You want a spline fit, (spline interpolation) I believe.

Spline fits describe regions of the data using a set of control points from the data, then apply a polynomial interpolation between control points. More control points gives you a more accurate fit, less a more general fit. Splines are much more accurate than linear fits, faster to use than a general regression fit, better than a high-order polynomial because it won't do crazy things between control points.

I can't remember names off the top of my head, but there are some excellent fitting libraries in Java -- I suggest you look for one rather than writing your own function.


**EDIT: Libraries that might be useful: **

** Theory/code that may be useful: **

  • Spline applets with code: link
  • Arkan spline fitting for poly-lines to bezier splines
  • Theory of splines, and some math for fitting. More math, less code, might help if the libraries don't.

这篇关于插入数组(或两个)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆