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 代码格式

cs 复制代码
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]);
            }
        }
    }
}
相关推荐
有点。6 小时前
C++(枚举法一练习题)
开发语言·c++·算法
Klong.k6 小时前
如何避免Bean的线程安全问题
java·开发语言
黎阳之光6 小时前
视听融合新范式!黎阳之光打破视觉边界,声影协同赋能全域智慧管控
大数据·人工智能·物联网·算法·数字孪生
接着奏乐接着舞6 小时前
【无标题】
开发语言·前端·javascript
iiiiyu7 小时前
集合进阶(Map集合)
java·大数据·开发语言·数据结构·编程语言
玖釉-7 小时前
栈——栈的定义及基本操作
c++·windows·算法·图形渲染
月落归舟7 小时前
并发编程之volatile深度解析(二)
java·开发语言·volatile
伽蓝_游戏7 小时前
第二章:深入 Unity 资源导入管线 (Asset Import Pipeline)
游戏·unity·c#·游戏引擎·游戏程序
来恩10037 小时前
Java Web三大作用域对象
java·开发语言·前端