你可以做一個線性外推,如: -
public static decimal ExtrapolateFrom(int f, int s, decimal f1, decimal s2, int value)
{
return (s2-f1)/((s-(decimal)f)/(value-(decimal)f))+f1;
}
public static decimal ExtrapolateFrom(List<Tuple<int, decimal>> table, int value)
{
if(table.Count < 2) throw new Exception("Not enough values to extrapolate from");
var result = table.Select((x, i) => new { x, i }).Where(x => x.x.Item1 >= value).Select(x => x.i).ToList();
var index = result.Any()? result.First() : table.Count-1;
if (index < 1) index = 1;
return ExtrapolateFrom(table[index - 1].Item1, table[index].Item1, table[index - 1].Item2,table[index].Item2, value);
}
private static void Main(string[] args)
{
var table = new List<Tuple<int, decimal>>()
{
new Tuple<int, decimal>(0, 0.0M),
new Tuple<int, decimal>(100, 5.0M),
new Tuple<int, decimal>(200, 6.0M),
new Tuple<int, decimal>(300, 9.0M),
new Tuple<int, decimal>(500, 11.0M),
};
Console.WriteLine(ExtrapolateFrom(table, 50));
Console.WriteLine(ExtrapolateFrom(table, 400));
Console.WriteLine(ExtrapolateFrom(table, 600));
}
,需要一個表中的ExtrapolateFrom
作用: -
- 檢查,以確保那裏有至少2截斷從
- 出土文物推斷表格中的第一個截止點大於您要轉換的值
- 檢查我們是否有值大於表中指定,在這種情況下使用的最後兩個臨界值
- 如果我們有小於表指定的值,在這種情況下,使用前兩個截止
- 使用兩個表點做線性外推。
該怎麼做? – 2013-05-02 20:08:48
如何將毫伏與表格中的數據關聯以獲得溫度。 – FeliceM 2013-05-02 20:12:09
你應該把你的問題的評論,而不是作爲評論 – 2013-05-02 20:57:22