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, yv0, 2)

{

}

public override double rawinterp(int j, double x)

{

if (xxj == xxj + 1)

{

return yyj;

}

else

{

return yyj + ((x - xxj) / (xxj + 1 - xxj)) * (yyj + 1 - yyj);

}

}

}

}

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]);
            }
        }
    }
}
相关推荐
hez20102 小时前
在 .NET 上构建超大托管数组
c#·.net·.net core·gc·clr
先吃饱再说6 小时前
判断回文字符串,从一行代码到双指针优化
算法
黄敬峰8 小时前
深入理解算法核心:从递归思想、数组扁平化到快速排序
算法
得物技术10 小时前
从狂野代码到按目标生产:得物推荐 AI Harness 的工程化实践|AICon 演讲整理
人工智能·算法·架构
AI小老六13 小时前
SkillOpt 架构拆解:把 Skill 文本当参数,用执行轨迹训练 Agent
后端·算法·ai编程
胡萝卜术14 小时前
从“分数打架”到“排名投票”:为什么你的ChatBI必须用RRF?
算法·设计模式·面试
Asize14 小时前
初识DFS 与 BFS:递归、队列与图遍历
算法
罗西的思考1 天前
机器人 / 强化学习】HIL-SERL:人类在环驱动的具身智能进化框架
人工智能·算法·机器学习
美团技术团队1 天前
LongCat 开源 VitaBench 2.0:长期动态智能体基准新标杆
人工智能·算法