2
回答
Spline插值C#实现
百度AI开发者大赛带你边学边开发,赢100万奖金,加群:418589053   

/// <summary>
        ///  x length=n*m
        ///  y length=n*m
        ///  z length=n*m
        ///  z(i)=f(x(i),y(i)) i=0.....n*m-1 
        /// </summary>
        private void Spline_c()
        {
            int n = 10, m = 12;
            int len = n * m;
            double[] x = new double[len];
            int xIndex = 0;
            double[] y = new double[len];
            int yIndex = 0;

            double[] f = new double[len];
            int fIndex = 0;

            for (int i1 = 0; i1 < n; i1++)
            {
                for (int j1 = 0; j1 < m; j1++)
                {
                    x[xIndex] = j1;
                    xIndex++;
                    y[yIndex] =i1*new Random().Next();
                    yIndex++;
                    f[fIndex] = 100*new Random().NextDouble();
                    fIndex++;
                }
            }
            // spline  f(x,y,f)  如何实现Spline插值
        }

<无标签>
举报
pollux
发帖于4年前 2回/1K+阅
共有2个答案 最后回答: 4年前

各位,麻烦给看下,以前在开源库alglib中看到有spline插值

 /**
            * first D elements store D values at (X[0],Y[0])
            * next D elements store D values at (X[1],Y[0])
             *
             * * ...
            * next D elements store D values at (X[0],Y[1])
            * next D elements store D values at (X[1],Y[1])
             */
            double[] x = new double[] { 2,5};
            double[] y = new double[] { 1,2};
            double[] f = new double[] { 1, 2, 3, 4};
            alglib.spline2dinterpolant s;
            double[] vr;
            alglib.spline2dbuildbicubicv(x, 2, y, 2, f, 1, out s);
            alglib.spline2dcalcv(s, 0.5, 0.3, out vr);
            System.Console.WriteLine("{0}", alglib.ap.format(vr, 4));

顶部