本文主要是介绍C#,数值计算——插值和外推,分段线性插值(Linear_interp)的计算方法与源程序,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1 文本格式
using System;
namespace Legalsoft.Truffer
{
/// <summary>
/// 分段线性插值
/// Piecewise linear interpolation object.
/// Construct with x and y vectors, then call interp for interpolated values.
/// </summary>
public class Linear_interp : Base_interp
{
public Linear_interp(double[] xv, double[] yv) : base(xv, yv[0], 2)
{
}
public override double rawinterp(int j, double x)
{
if (xx[j] == xx[j + 1])
{
return yy[j];
}
else
{
return yy[j] + ((x - xx[j]) / (xx[j + 1] - xx[j])) * (yy[j + 1] - yy[j]);
}
}
}
}
2 代码格式
using System;namespace Legalsoft.Truffer
{/// <summary>/// 分段线性插值/// Piecewise linear interpolation object./// Construct with x and y vectors, then call interp for interpolated values./// </summary>public class Linear_interp : Base_interp{public Linear_interp(double[] xv, double[] yv) : base(xv, yv[0], 2){}public override double rawinterp(int j, double x){if (xx[j] == xx[j + 1]){return yy[j];}else{return yy[j] + ((x - xx[j]) / (xx[j + 1] - xx[j])) * (yy[j + 1] - yy[j]);}}}
}
这篇关于C#,数值计算——插值和外推,分段线性插值(Linear_interp)的计算方法与源程序的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!