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]);
            }
        }
    }
}
相关推荐
**K2 分钟前
C++ 智能指针使用不当导致内存泄漏问题
开发语言·c++·算法
Leo-Peng5 分钟前
辐射神经场算法——Instant-NGP / Mipi-NeRF 360 / 3D Gaussian Splatting
算法·nerf·3d gaussian
菌菌巧乐兹6 分钟前
C# 快速排序算法的详细讲解
算法·排序算法
u01040583615 分钟前
如何利用Java Stream API简化集合操作?
java·开发语言
湫兮之风24 分钟前
C++:.front()函数作用
开发语言·c++
TechQuester30 分钟前
解决GPT-4o耗电难题!DeepMind新算法训练效率提升13倍,能耗降低10倍!
java·c++·人工智能·python·算法·chatgpt
流星白龙39 分钟前
【C语言题目】34.猜凶手
c语言·开发语言
XSTIT39 分钟前
数据结构--二叉树相关题2(OJ)
数据结构·算法
青青草原上的梦想家43 分钟前
游戏开发面试题7
开发语言·游戏·面试
NaRciCiSSuS44 分钟前
第一章-JavaScript简介
开发语言·javascript·ecmascript