Ejemplo n.º 1
0
        /// <summary>
        /// Get value of preimage by value of image
        /// </summary>
        /// <param name="p">Value of image</param>
        /// <param name="n">Degree of interpolation polynome</param>
        /// <param name="table">Table set function</param>
        /// <returns>Value of preimage</returns>
        public static double Preimage_II(double p, int n, ref double[,] table)
        {
            var m = table.GetLength(0) - 1;
            var a = table[0, 0];
            var b = table[m, 0];

            if (Math.Abs(Lab2.Lagrange(a, n, ref table) - p) < Eps)
            {
                return(a);
            }

            if (Math.Abs(Lab2.Lagrange(b, n, ref table) - p) < Eps)
            {
                return(b);
            }

            var mid = 0.0;

            while (Math.Abs(b - a) > Eps)
            {
                mid = (b + a) / 2;

                if ((Lab2.Lagrange(a, n, ref table) - p) *
                    (Lab2.Lagrange(mid, n, ref table) - p) < 0)
                {
                    b = mid;
                }
                else
                {
                    a = mid;
                }
            }

            return(mid);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get value of preimage by value of image
        /// </summary>
        /// <param name="p">Value of image</param>
        /// <param name="n">Degree of interpolation polynome</param>
        /// <param name="table">Table set function</param>
        /// <returns>Value of preimage</returns>
        public static double Preimage_I(double p, int n, ref double[,] table)
        {
            var swappedTable = Tools.Table.SwapColumns(table);

            return(Lab2.Lagrange(p, n, ref swappedTable));
        }