在Visual Basic .NET中进行插值/外推 [英] Interpolate / Extrapolate in Visual Basic .NET
本文介绍了在Visual Basic .NET中进行插值/外推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Visual Basic 2010的新手,我做了很多搜索,但确实停留在某一时刻.我以为我想问一下这里是否有一个友善的灵魂可以将我指向正确的方向!
我有一个X,Y值数组,其中所有X都是已知的,但只有一些Y已知. Y值表示直线段上的点,我希望能够填充Y间隙.定义的Y值之间的线性插值看起来应该可行,我也希望它在定义的值之外线性外推.
我对数学有些了解,但是我很难将其放入代码中,除非它变得难以理解.
我还看到在.Net中,DrawLine和DrawCurve可以在点之间绘制.我已经尝试过了,但是我不知道如何访问线/曲线的新绘制之间"值,也无法在定义的点之外绘制任何线.
我肯定想念一些明显的东西.有任何想法吗?
谢谢!
................................................... ....................
TRK3-没有点固定在石头上,所以我不需要最小二乘方拟合.我可能需要x = y * m + b.感谢您的帮助!
小沃尔特·费尔(Walt Fair,Jr)-这就是我追求的中间点-当显示给您时很明显-谢谢!
据我现在所见,我将在数组中查找Y的第一个和最后一个实值,然后用公式在点之间进行插值.然后,我将必须推断出两条终点线,我想将每一端的2个点用作斜率.奇怪的是,我还没有找到任何代码来执行此操作.
不管怎样,一切都欢呼吧!
解决方案
插值的公式很简单,假设您的值以X(i)
的顺序排列,并且Y(i)
对应于X(i)
,Y(i) = Y(i-1) + (X(i) - X(i-1))*(Y(i+1) - Y(i-1))/(X(i+1) - X(i-1))
,其中X
和Y
的值在i-1
和i+1
处都是已知的.
就DrawLine
和DrawCurve
方法而言,它们绘制在屏幕(或图形上下文)上.它们不会创建易于读取的点数组.
Y值是不是被测为直线,但可能由于测量误差而变化吗?
如果是这样,那么计算最小二乘拟合线是您的最佳选择.这是描述算法的好链接,并提供了vb代码:
http://www.vb-helper.com/howto_linear_least_squares.html [ 解决方案
The formula for interpolation is straight forward, assuming your values are inX(i)
in sorted order andY(i)
corresponds toX(i)
,Y(i) = Y(i-1) + (X(i) - X(i-1))*(Y(i+1) - Y(i-1))/(X(i+1) - X(i-1))
, where the values of bothX
andY
are known ati-1
andi+1
.
As far as theDrawLine
andDrawCurve
methods, they draw to the screen (or a graphics context). They don''t create an array of points that you can readily read.
Are the Y values something measured that are supposed to be in a straight line but might vary due to measurement errors?
If so, calculating the least-squares-fit line is your best bet. Here''s a good link that describes the algorithm and gives you the vb code:
http://www.vb-helper.com/howto_linear_least_squares.html[^]
The algorithm in that link gives you the equation of the best fit line in terms of a slope (m) and intercept (b) such that:
x = y * m + b
So if you have that, you can calculate y for any given x.
If on the other hand the data isn''t expected to be a line, but you just want to fill in the missing y''s by linearly interpolating, then Walt Fair, Jr.''s solution works great.
这篇关于在Visual Basic .NET中进行插值/外推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文