当前位置: 首页 > article >正文

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 代码格式

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;
        }
    }
}


http://www.kler.cn/a/131923.html

相关文章:

  • 助力水泥基建裂痕自动化巡检,基于yolov5融合ASPP开发构建多尺度融合目标检测识别系统
  • TableUtilCache:针对CSV表格进行的缓存
  • Jupyter Notebook的下载安装与使用教程_Python数据分析与可视化
  • 20231117在ubuntu20.04下使用ZIP命令压缩文件夹
  • 服务器集群配置LDAP统一认证高可用集群(配置tsl安全链接)-centos9stream-openldap2.6.2
  • 什么是BT种子!磁力链接又是如何工作的?
  • 基于SSM的中小型企业财务管理设计与实现
  • 基于SSM的智能仓储系统研究与设计
  • WPF打开对话框选择文件、选择文件夹
  • 数组、list、set、map集合之间相互转换
  • C++基础从0到1入门编程(二)
  • 免费开源的区域屏幕录制(gif转换)工具(支持编辑功能)
  • 第三十三节——组合式API生命周期
  • node 第十八天 中间件express-session实现会话密钥
  • 【MATLAB源码-第80期】基于蚯蚓优化算法(EOA)的无人机三维路径规划,输出做短路径图和适应度曲线
  • gitlub 加载慢问题处理
  • 航天联志Aisino-AISINO26081R服务器通过调BIOS用U盘重新做系统(windows系统通用)
  • Julia累加和累乘
  • Java实体类与返给前端变量名字母大小写不一样问题
  • 在WPF应用程序集中添加新文件时,Page和Window有什么区别