Exemple #1
0
        /// <summary>
        /// Evaluation of cubic polynomial by brute force
        /// </summary>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="k1"></param>
        /// <param name="k2"></param>
        /// <param name="plotter"></param>
        /// <param name="res"></param>
        protected void interpolate_brute_force(double x1, double y1, double x2, double y2, double k1, double k2, PointPlotter plotter, double res)
        {
            Coefficients coeff = new Coefficients();

            cubic_coefficients(x1, y1, x2, y2, k1, k2, coeff);

            // Calculate each point
            for (double x = x1; x <= x2; x += res)
            {
                double y = ((coeff.a * x + coeff.b) * x + coeff.c) * x + coeff.d;
                plotter.plot(x, y);
            }
        }
Exemple #2
0
        /// <summary>
        /// Evaluation of cubic polynomial by forward differencing
        /// </summary>
        /// <param name="x1"></param>
        /// <param name="y1"></param>
        /// <param name="x2"></param>
        /// <param name="y2"></param>
        /// <param name="k1"></param>
        /// <param name="k2"></param>
        /// <param name="plotter"></param>
        /// <param name="res"></param>
        protected void interpolate_forward_difference(double x1, double y1, double x2, double y2, double k1, double k2, PointPlotter plotter, double res)
        {
            Coefficients coeff = new Coefficients();

            cubic_coefficients(x1, y1, x2, y2, k1, k2, coeff);

            double y   = ((coeff.a * x1 + coeff.b) * x1 + coeff.c) * x1 + coeff.d;
            double dy  = (3 * coeff.a * (x1 + res) + 2 * coeff.b) * x1 * res + ((coeff.a * res + coeff.b) * res + coeff.c) * res;
            double d2y = (6 * coeff.a * (x1 + res) + 2 * coeff.b) * res * res;
            double d3y = 6 * coeff.a * res * res * res;

            // Calculate each point
            for (double x = x1; x <= x2; x += res)
            {
                plotter.plot(x, y);
                y   += dy;
                dy  += d2y;
                d2y += d3y;
            }
        }