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 分钟前
【Rust宏编程】Rust有关宏编程底层原理解析与应用实战
开发语言·后端·rust·rust宏·宏编程·rust宏编程
yorushika_28 分钟前
python打卡训练营打卡记录day45
开发语言·python·深度学习·tensorboard
封奚泽优30 分钟前
使用Python进行函数作画
开发语言·python
aningxiaoxixi37 分钟前
JAVA之 Lambda
java·开发语言
xphjj1 小时前
树形数据模糊搜索
前端·javascript·算法
宝桥南山1 小时前
DeepSeek - 尝试一下GitHub Models中的DeepSeek
microsoft·ai·微软·c#·github·.net
Once_day1 小时前
代码训练LeetCode(24)数组乘积
算法·leetcode
come112341 小时前
Claude 写 PHP 项目的完整小白教程
开发语言·php
虾球xz1 小时前
CppCon 2015 学习:Concurrency TS Editor’s Report
开发语言·c++·学习
板鸭〈小号〉2 小时前
命名管道实现本地通信
开发语言·c++