Beispiel #1
0
        /// <summary>
        /// интерполяция
        /// </summary>
        /// <param name="?"></param>
        public static void interpolation(Vector[] data,
                                     double x,
                                     double[] mt,
                                     out double ys)
        {
            int i = 1;
            double d, h1, p1, ra, ysa;

            while (x > data[i].X)
                i++;

            int j = i - 1;
            d = data[i].X - data[j].X;
            h1 = x - data[j].X;
            ra = data[i].X - x;
            p1 = d * d / 6;
            ys = (mt[j] * Math.Pow(ra, 3) + mt[i] * Math.Pow(h1, 3)) / 6 / d;
            ysa = (data[j].Y - mt[j] * p1) * ra;
            ysa = ysa + (data[i].Y - mt[i] * p1) * h1;
            ys = ys + ysa / d;
        }
Beispiel #2
0
        /// <summary>
        /// интерполяция кубическими сплайнами
        /// </summary>
        /// <param name="term"></param>
        /// <param name="eject"></param>
        /// <param name="num"></param>
        /// <param name="m"></param>
        /// <param name="nn"></param>
        public static void interpolationCubicSplineMethod(Vector[] term,
                                                  Vector[] eject,
                                                  int num,
                                                  ref double[] m,
                                                  int nn)
        {
            double[] l = new double[nn];
            double[] s = new double[nn];
            double[] r = new double[nn];
            double d = 0, e = 0, h1, p1, f5;

            for (int h = 0; h < nn; h++)
            {
                l[h] = 0;
                s[h] = 0;
                r[h] = 0;
            }

            if (num == 1)
            {
                d = term[0].X - term[1].X;
                e = (term[1].Y - term[0].Y) / d;
            }
            else if (num == 2)
            {
                d = eject[1].X - eject[0].X;
                e = (eject[1].Y - eject[0].Y) / d;
            }

            for (int i = 1; i < nn - 1; i++)
            {
                h1 = d;
                f5 = e;

                if (num == 1)
                {
                    d = term[i + 1].X - term[i].X;
                    e = (term[i + 1].Y - term[i].Y) / d;
                }
                else if (num == 2)
                {
                    d = eject[i + 1].X - eject[i].X;
                    e = (eject[i + 1].Y - eject[i].Y) / d;
                }

                l[i] = d / (d + h1);
                r[i] = 1 - l[i];
                s[i] = 6 * (e - f5) / (h1 + d);
            }

            for (uint i = 1; i < nn - 1; i++)
            {
                p1 = 1 / (r[i] * l[i - 1] + 2);
                l[i] = -l[i] * p1;
                s[i] = (s[i] - r[i] * s[i - 1]) * p1;
            }
            m[nn - 1] = 0;
            l[nn - 2] = s[nn - 2];
            m[nn - 2] = l[nn - 2];

            for (int i = nn - 3; i >= 0; i--)
            {
                l[i] = l[i] * l[i + 1] + s[i];
                m[i] = l[i];
            }
        }