在Visual C#中查找两个数组之间的插值 [英] Find Interpolation Value Between Two Arrays in Visual C#
问题描述
我想使用任何数学方法找到插值;线性,2D或更复杂。
我有两个根类型,它们有双重类型元素;第一个是X数组,下一个是Y数组。
每个X数组的元素对应于Y数组的元素。像这样:
双倍[] X = {1.2,4.5,23,86};
double [] Y = {19,75,123,344};
$
作为一个例子,我想知道Y数组中"10"的值是多少。要在X数组中表示的值。
请帮助我,谢谢。
< blockquote>
从这个简单的方法开始:
double x = 10;
int i = Array.FindIndex(X,k => x< = k);
double y = Y [i - 1] +(x - X [i - 1])*(Y [i] - Y [i - 1])/(X [i] - X [i - 1 ]);
I want to find an interpolation value using any math method; linear, 2D or more complex.
I have two root arrays which have double type elements; the first one is X array and the next one is Y array.
The element of each X array corresponds to an element of Y array. Like this:
double [] X = {1.2,4.5,23,86};
double [] Y = {19,75,123,344};
As an example, I would like to find out what value will be in the Y array for "10" value to be represented in the X array.
Please help me, thanks.
Start with this simple method:
double x = 10; int i = Array.FindIndex( X, k => x <= k ); double y = Y[i - 1] + ( x - X[i - 1] ) * ( Y[i] - Y[i - 1] ) / ( X[i] - X[i - 1] );
这篇关于在Visual C#中查找两个数组之间的插值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!