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);
        }
    }
}
相关推荐
新生农民40 分钟前
30分钟解决8道算法题
java·数据结构·算法
bbc1212261 小时前
2025/4/23 心得
数据结构·算法
ghost1432 小时前
C#学习第18天:特性(Attributes)
开发语言·学习·c#
WaitWaitWait015 小时前
LeetCode每日一题4.20
算法·leetcode
蒟蒻小袁5 小时前
力扣面试150题--有效的括号和简化路径
算法·leetcode·面试
跳跳糖炒酸奶6 小时前
第十五讲、Isaaclab中在机器人上添加传感器
人工智能·python·算法·ubuntu·机器人
明月看潮生8 小时前
青少年编程与数学 02-018 C++数据结构与算法 06课题、树
数据结构·c++·算法·青少年编程·编程与数学
小指纹8 小时前
动态规划(一)【背包】
c++·算法·动态规划
_安晓8 小时前
数据结构 -- 图的应用(一)
数据结构·算法·图论
阳洞洞8 小时前
leetcode 二分查找应用
算法·leetcode·二分查找