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

1 文本格式

using System;

namespace Legalsoft.Truffer
{
    ///


    /// 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.
    ///

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

using System;

namespace Legalsoft.Truffer
{
    /// 
    /// 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.
    /// 
    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);
        }
    }
}

你可能感兴趣的:(C#数值计算,Numerical,Recipes,c#,算法,数值计算)