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;
        }
    }
}
相关推荐
浮生如梦_1 小时前
Halcon基于laws纹理特征的SVM分类
图像处理·人工智能·算法·支持向量机·计算机视觉·分类·视觉检测
△曉風殘月〆1 小时前
WPF MVVM入门系列教程(二、依赖属性)
c#·wpf·mvvm
XiaoLeisj2 小时前
【JavaEE初阶 — 多线程】单例模式 & 指令重排序问题
java·开发语言·java-ee
励志成为嵌入式工程师3 小时前
c语言简单编程练习9
c语言·开发语言·算法·vim
逐·風3 小时前
unity关于自定义渲染、内存管理、性能调优、复杂物理模拟、并行计算以及插件开发
前端·unity·c#
捕鲸叉3 小时前
创建线程时传递参数给线程
开发语言·c++·算法
A charmer3 小时前
【C++】vector 类深度解析:探索动态数组的奥秘
开发语言·c++·算法
Peter_chq3 小时前
【操作系统】基于环形队列的生产消费模型
linux·c语言·开发语言·c++·后端
wheeldown4 小时前
【数据结构】选择排序
数据结构·算法·排序算法
记录成长java5 小时前
ServletContext,Cookie,HttpSession的使用
java·开发语言·servlet