C#,数值计算——插值和外推,双线性插值(Bilin_interp)的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer

{

/// <summary>

/// 双线性插值

/// interpolation routines for two dimensions

/// Object for bilinear interpolation on a matrix.

/// Construct with a vector of x1.

/// values, a vector of x2 values,

/// and a matrix of tabulated function values yij

/// Then call interp for interpolated values.

/// </summary>

public class Bilin_interp

{

private int m { get; set; }

private int n { get; set; }

private double[,] y { get; set; }

private Linear_interp x1terp { get; set; } = null;

private Linear_interp x2terp { get; set; } = null;

public Bilin_interp(double[] x1v, double[] x2v, double[,] ym)

{

this.m = x1v.Length;

this.n = x2v.Length;

this.y = ym;

this.x1terp = new Linear_interp(x1v, x1v);

this.x2terp = new Linear_interp(x2v, x2v);

}

public double interp(double x1p, double x2p)

{

int i = x1terp.cor > 0 ? x1terp.hunt(x1p) : x1terp.locate(x1p);

int j = x2terp.cor > 0 ? x2terp.hunt(x2p) : x2terp.locate(x2p);

double t = (x1p - x1terp.xx[i]) / (x1terp.xx[i + 1] - x1terp.xx[i]);

double u = (x2p - x2terp.xx[j]) / (x2terp.xx[j + 1] - x2terp.xx[j]);

double yy = (1.0 - t) * (1.0 - u) * y[i, j] + t * (1.0 - u) * y[i + 1, j] + (1.0 - t) * u * y[i, j + 1] + t * u * y[i + 1, j + 1];

return yy;

}

}

}

2 代码格式

cs 复制代码
using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// 双线性插值
    /// interpolation routines for two dimensions
    /// Object for bilinear interpolation on a matrix.
    /// Construct with a vector of x1.
    /// values, a vector of x2 values, 
    /// and a matrix of tabulated function values yij
    /// Then call interp for interpolated values.
    /// </summary>
    public class Bilin_interp
    {
        private int m { get; set; }
        private int n { get; set; }
        private double[,] y { get; set; }
        private Linear_interp x1terp { get; set; } = null;
        private Linear_interp x2terp { get; set; } = null;

        public Bilin_interp(double[] x1v, double[] x2v, double[,] ym)
        {
            this.m = x1v.Length;
            this.n = x2v.Length;
            this.y = ym;
            this.x1terp = new Linear_interp(x1v, x1v);
            this.x2terp = new Linear_interp(x2v, x2v);
        }

        public double interp(double x1p, double x2p)
        {
            int i = x1terp.cor > 0 ? x1terp.hunt(x1p) : x1terp.locate(x1p);
            int j = x2terp.cor > 0 ? x2terp.hunt(x2p) : x2terp.locate(x2p);
            double t = (x1p - x1terp.xx[i]) / (x1terp.xx[i + 1] - x1terp.xx[i]);
            double u = (x2p - x2terp.xx[j]) / (x2terp.xx[j + 1] - x2terp.xx[j]);
            double yy = (1.0 - t) * (1.0 - u) * y[i, j] + t * (1.0 - u) * y[i + 1, j] + (1.0 - t) * u * y[i, j + 1] + t * u * y[i + 1, j + 1];
            return yy;
        }
    }
}
相关推荐
SoraLuna15 分钟前
「Mac畅玩鸿蒙与硬件47」UI互动应用篇24 - 虚拟音乐控制台
开发语言·macos·ui·华为·harmonyos
xlsw_21 分钟前
java全栈day20--Web后端实战(Mybatis基础2)
java·开发语言·mybatis
Dream_Snowar1 小时前
速通Python 第三节
开发语言·python
XH华2 小时前
初识C语言之二维数组(下)
c语言·算法
南宫生2 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
不想当程序猿_2 小时前
【蓝桥杯每日一题】求和——前缀和
算法·前缀和·蓝桥杯
高山我梦口香糖2 小时前
[react]searchParams转普通对象
开发语言·前端·javascript
落魄君子2 小时前
GA-BP分类-遗传算法(Genetic Algorithm)和反向传播算法(Backpropagation)
算法·分类·数据挖掘
菜鸡中的奋斗鸡→挣扎鸡3 小时前
滑动窗口 + 算法复习
数据结构·算法
信号处理学渣3 小时前
matlab画图,选择性显示legend标签
开发语言·matlab