在Visual C#中查找两个数组之间的插值 [英] Find Interpolation Value Between Two Arrays in Visual C#

查看:60
本文介绍了在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屋!

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