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]);
            }
        }
    }
}
相关推荐
jimy13 分钟前
C语言中的 “size_t ”类型
c语言·开发语言
techdashen4 分钟前
Cloudflare 如何用 Rust 构建一个高性能解释器
开发语言·后端·rust
无敌秋13 分钟前
C++ 抽象工厂模式实战指南
开发语言·c++·抽象工厂模式
Chat_zhanggong34520 分钟前
主推NT98336BG作用有哪些?
嵌入式硬件·算法
小书房21 分钟前
Kotlin使用体验及理解1
android·开发语言·kotlin
勤劳的进取家30 分钟前
传输层基础
运维·开发语言·学习·php
wangbing112534 分钟前
Java处理csv文件总是丢数据
java·开发语言·python
Rust语言中文社区34 分钟前
【Rust日报】2026-04-28 Pacquet:pnpm 的 Rust 重写版本
开发语言·后端·rust
Run_Teenage39 分钟前
算法:线段树
算法
Westward-sun.41 分钟前
YOLOv2算法全方位解析:从BatchNorm到聚类先验框的九大改进
算法·yolo·聚类