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;
        }
    }
}
相关推荐
MiyamiKK573 分钟前
leetcode_字符串 409. 最长回文串
数据结构·算法·leetcode
Biomamba生信基地3 分钟前
R语言基础| 回归分析
开发语言·回归·r语言
黑客-雨17 分钟前
从零开始:如何用Python训练一个AI模型(超详细教程)非常详细收藏我这一篇就够了!
开发语言·人工智能·python·大模型·ai产品经理·大模型学习·大模型入门
Pandaconda22 分钟前
【Golang 面试题】每日 3 题(三十九)
开发语言·经验分享·笔记·后端·面试·golang·go
半盏茶香23 分钟前
扬帆数据结构算法之雅舟航程,漫步C++幽谷——LeetCode刷题之移除链表元素、反转链表、找中间节点、合并有序链表、链表的回文结构
数据结构·c++·算法
加油,旭杏26 分钟前
【go语言】变量和常量
服务器·开发语言·golang
行路见知26 分钟前
3.3 Go 返回值详解
开发语言·golang
xcLeigh30 分钟前
WPF实战案例 | C# WPF实现大学选课系统
开发语言·c#·wpf
one99633 分钟前
.net 项目引用与 .NET Framework 项目引用之间的区别和相同
c#·.net·wpf
xcLeigh40 分钟前
WPF基础 | WPF 布局系统深度剖析:从 Grid 到 StackPanel
c#·wpf