C#,数值计算——多项式插值与外推插值(Poly2D_interp)的计算方法与源程序

1 文本格式

using System;

namespace Legalsoft.Truffer

{

/// <summary>

/// Object for two-dimensional polynomial interpolation on a matrix.Construct

/// with a vector of x1 values, a vector of x2 values, a matrix of tabulated

/// function values yij , and integers to specify the number of points to use

/// locally in each direction. Then call interp for interpolated values.

/// </summary>

public class Poly2D_interp

{

private int m { get; set; }

private int n { get; set; }

private int mm { get; set; }

private int nn { get; set; }

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

private double[] yv { get; set; }

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

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

public Poly2D_interp(double[] x1v, double[] x2v, double[,] ym, int mp, int np)

{

this.m = x1v.Length;

this.n = x2v.Length;

this.mm = mp;

this.nn = np;

this.y = ym;

this.yv = new double[m];

this.x1terp = new Poly_interp(x1v, yv, mm);

this.x2terp = new Poly_interp(x2v, x2v, nn);

}

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

for (int k = i; k < i + mm; k++)

{

// x2terp.yy = (y[k, 0]);

x2terp.yy = Globals.CopyFrom(k, y);

yv[k] = x2terp.rawinterp(j, x2p);

}

return x1terp.rawinterp(i, x1p);

}

}

}

2 代码格式

cs 复制代码
using System;

namespace Legalsoft.Truffer
{
    /// <summary>
    /// Object for two-dimensional polynomial interpolation on a matrix.Construct
    /// with a vector of x1 values, a vector of x2 values, a matrix of tabulated
    /// function values yij , and integers to specify the number of points to use
    /// locally in each direction. Then call interp for interpolated values.
    /// </summary>
    public class Poly2D_interp
    {
        private int m { get; set; }
        private int n { get; set; }
        private int mm { get; set; }
        private int nn { get; set; }
        private double[,] y { get; set; }
        private double[] yv { get; set; }
        private Poly_interp x1terp { get; set; } = null;
        private Poly_interp x2terp { get; set; } = null;

        public Poly2D_interp(double[] x1v, double[] x2v, double[,] ym, int mp, int np)
        {
            this.m = x1v.Length;
            this.n = x2v.Length;
            this.mm = mp;
            this.nn = np;
            this.y = ym;
            this.yv = new double[m];
            this.x1terp = new Poly_interp(x1v, yv, mm);
            this.x2terp = new Poly_interp(x2v, x2v, nn);
        }

        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);
            for (int k = i; k < i + mm; k++)
            {
                // x2terp.yy = (y[k, 0]);
                x2terp.yy = Globals.CopyFrom(k, y);
                yv[k] = x2terp.rawinterp(j, x2p);
            }
            return x1terp.rawinterp(i, x1p);
        }
    }
}
相关推荐
利刃大大24 分钟前
【回溯+剪枝】找出所有子集的异或总和再求和 && 全排列Ⅱ
c++·算法·深度优先·剪枝
来恩10031 小时前
C# 类与对象详解
开发语言·c#
Rachela_z1 小时前
代码随想录算法训练营第十四天| 二叉树2
数据结构·算法
细嗅蔷薇@1 小时前
迪杰斯特拉(Dijkstra)算法
数据结构·算法
追求源于热爱!1 小时前
记5(一元逻辑回归+线性分类器+多元逻辑回归
算法·机器学习·逻辑回归
ElseWhereR1 小时前
C++ 写一个简单的加减法计算器
开发语言·c++·算法
Smark.2 小时前
Gurobi基础语法之 addConstr, addConstrs, addQConstr, addMQConstr
算法
S-X-S2 小时前
算法总结-数组/字符串
java·数据结构·算法
Joyner20183 小时前
python-leetcode-从中序与后序遍历序列构造二叉树
算法·leetcode·职场和发展
因兹菜3 小时前
[LeetCode]day9 203.移除链表元素
算法·leetcode·链表