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;
        }
    }
}
相关推荐
AI原吾12 分钟前
探索PyAV:Python中的多媒体处理利器
开发语言·python·ai·pyav
DK2215117 分钟前
机器学习系列-----主成分分析(PCA)
人工智能·算法·机器学习
oliveira-time23 分钟前
爬虫学习8
开发语言·javascript·爬虫·python·算法
矛取矛求1 小时前
string接口的深度理解(内附思维导图)
c语言·开发语言·c++·接口·string
代码小鑫1 小时前
A15基于Spring Boot的宠物爱心组织管理系统的设计与实现
java·开发语言·spring boot·后端·毕业设计·宠物
点云侠1 小时前
二维椭圆拟合算法及推导过程
开发语言·c++·算法·计算机视觉·matlab
海绵波波1071 小时前
Webserver(4.5)复用
android·开发语言·javascript
一直学习永不止步1 小时前
LeetCode题练习与总结:迷你语法分析器--385
java·数据结构·算法·leetcode·字符串··深度优先搜索
stm 学习ing1 小时前
FPGA 第二讲 初始FPGA
c语言·开发语言·stm32·fpga开发·c#·visual studio·嵌入式实时数据库
howard20051 小时前
初试Lisp语言
开发语言·lisp