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);
        }
    }
}
相关推荐
XH华2 小时前
初识C语言之二维数组(下)
c语言·算法
南宫生2 小时前
力扣-图论-17【算法学习day.67】
java·学习·算法·leetcode·图论
不想当程序猿_2 小时前
【蓝桥杯每日一题】求和——前缀和
算法·前缀和·蓝桥杯
落魄君子2 小时前
GA-BP分类-遗传算法(Genetic Algorithm)和反向传播算法(Backpropagation)
算法·分类·数据挖掘
菜鸡中的奋斗鸡→挣扎鸡3 小时前
滑动窗口 + 算法复习
数据结构·算法
Lenyiin3 小时前
第146场双周赛:统计符合条件长度为3的子数组数目、统计异或值为给定值的路径数目、判断网格图能否被切割成块、唯一中间众数子序列 Ⅰ
c++·算法·leetcode·周赛·lenyiin
郭wes代码3 小时前
Cmd命令大全(万字详细版)
python·算法·小程序
scan7243 小时前
LILAC采样算法
人工智能·算法·机器学习
菌菌的快乐生活3 小时前
理解支持向量机
算法·机器学习·支持向量机
大山同学4 小时前
第三章线性判别函数(二)
线性代数·算法·机器学习