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]);
            }
        }
    }
}
相关推荐
大佬,救命!!!几秒前
算法实现迭代2_堆排序
数据结构·python·算法·学习笔记·堆排序
程序员阿鹏16 分钟前
49.字母异位词分组
java·开发语言·leetcode
天桥下的卖艺者17 分钟前
R语言手搓一个计算生存分析C指数(C-index)的函数算法
c语言·算法·r语言
L X..34 分钟前
Unity 光照贴图异常修复笔记
unity·c#·游戏引擎
Espresso Macchiato36 分钟前
Leetcode 3715. Sum of Perfect Square Ancestors
算法·leetcode·职场和发展·leetcode hard·树的遍历·leetcode 3715·leetcode周赛471
Yurko131 小时前
【C语言】基本语法结构(上篇)
c语言·开发语言·学习
草莓熊Lotso1 小时前
《C++ Stack 与 Queue 完全使用指南:基础操作 + 经典场景 + 实战习题》
开发语言·c++·算法
孤客网络科技工作室1 小时前
Python - 100天从新手到大师:第五十七天获取网络资源及解析HTML页面
开发语言·python·html
武文斌771 小时前
复习总结最终版:计算机网络
linux·开发语言·学习·计算机网络
敲上瘾1 小时前
单序列和双序列问题——动态规划
c++·算法·动态规划