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]);
            }
        }
    }
}
相关推荐
jghhh011 分钟前
基于MATLAB的协同过滤推荐算法实现
开发语言·matlab·推荐算法
比特森林探险记4 分钟前
后端开发者快速入门react
开发语言·前端·javascript
重生之我是Java开发战士5 分钟前
【优选算法】滑动窗口:长度最小的子数组,无重复字符的最长子串,最大连续1的个数,将x减到0的最小操作数,水果成篮,异位词,串联所有单词的子串,最小覆盖子串
算法
马士兵教育11 分钟前
计算机专业学生入行IT行业,编程语言如何选择?
java·开发语言·c++·人工智能·python
码界奇点16 分钟前
基于eBPF技术的高性能网络防火墙系统设计与实现
开发语言·网络·毕业设计·php·wpf·go语言·源代码管理
一起养小猫18 分钟前
Flutter for OpenHarmony 实战:ListView与GridView滚动列表完全指南
开发语言·javascript·flutter
程序员清洒19 分钟前
Flutter for OpenHarmony:ListView — 高效滚动列表
开发语言·flutter·华为·鸿蒙
naruto_lnq20 分钟前
C++与自动驾驶系统
开发语言·c++·算法
啊阿狸不会拉杆25 分钟前
《数字信号处理》第6章:数字滤波器的基本概念及几种特殊滤波器
算法·matlab·信号处理·数字信号处理·dsp
wjs202429 分钟前
jEasyUI 启用行内编辑
开发语言