public void Oneeq5()
        {
            // Test case from http://www.polymath-software.com/library/nle/Oneeq5.htm
            Func <double, double> f1 = TR =>
            {
                const double ALPHA = 7.256;
                const double BETA  = 2.298E-3;
                const double GAMMA = 0.283E-6;
                const double DH    = -57798.0;
                return(DH + TR * (ALPHA + TR * (BETA / 2 + TR * GAMMA / 3)) - 298.0 * (ALPHA + 298.0 * (BETA / 2 + 298.0 * GAMMA / 3)));
            };

            double x = FindRoots.OfFunction(f1, 3000, 5000, 1e-10);

            Assert.AreEqual(4305.30991366774, x, 1e-5);
            Assert.AreEqual(0, f1(x), 1e-8);
        }
Beispiel #2
0
        public void ComplexRoots_TripleReal_AsPolynomial(double d, double c, double b, double a, double x1, double x2, double x3)
        {
            var expectedReal = new[] { x1, x2, x3 };
            var actual       = FindRoots.Polynomial(new[] { d, c, b, a });
            var actualReal   = Generate.Map(actual, x => x.Real);
            var actualImag   = Generate.Map(actual, x => x.Imaginary);

            Sorting.Sort(expectedReal);
            Sorting.Sort(actualReal, actualImag);
            Assert.That(actual.Length, Is.EqualTo(3));
            Assert.That(actualReal[0], Is.EqualTo(expectedReal[0]).Within(1e-14));
            Assert.That(actualImag[0], Is.EqualTo(0d).Within(1e-14));
            Assert.That(actualReal[1], Is.EqualTo(expectedReal[1]).Within(1e-14));
            Assert.That(actualImag[1], Is.EqualTo(0d).Within(1e-14));
            Assert.That(actualReal[2], Is.EqualTo(expectedReal[2]).Within(1e-14));
            Assert.That(actualImag[2], Is.EqualTo(0d).Within(1e-14));
        }
Beispiel #3
0
        public void Oneeq8()
        {
            // Test case from http://www.polymath-software.com/library/nle/Oneeq8.htm
            Func <double, double> f1 = v =>
            {
                const double a = 240;
                const double b = 40;
                const double c = 200;

                return(a * v * v + b * Math.Pow(v, 7 / 4) - c);
            };

            double x = FindRoots.OfFunction(f1, 0.01, 1);

            Assert.AreEqual(0.842524411168525, x, 1e-2);
            Assert.AreEqual(0, f1(x), 1e-5);
        }
Beispiel #4
0
        private void InvisibleSpheresSameHeight(Vector3[] centresSpheres, double[] thetas)
        {
            InitSingularityVariables(centresSpheres, thetas);

            double[] coefs = new double[3] {
                C, B, A
            };
            System.Numerics.Complex[] roots = FindRoots.Polynomial(coefs);
            for (int i = 0; i < roots.Length; i++)
            {
                if (roots[i].Imaginary == 0 && roots[i].Real < 0)
                {
                    endEffectorPosition = new Vector3(serviceConverter.ConvertDoubleToFloat(x_), serviceConverter.ConvertDoubleToFloat(roots[i].Real),
                                                      serviceConverter.ConvertDoubleToFloat(y_));
                }
            }
        }
Beispiel #5
0
        public void QuadraticExpanded(double u, double v, double t)
        {
            // t*(x+u)*(x+v) = t*u*v + t*(u+v)*x + t*x^2
            double  c = t * u * v, b = t * (u + v), a = t;
            var     x = FindRoots.Quadratic(c, b, a);
            Complex x1 = x.Item1, x2 = x.Item2;

            // Expected Roots: -u, -v
            Complex r1 = new Complex(-u, 0d), r2 = new Complex(-v, 0d);

            Assert.IsTrue(x1.AlmostEqualRelative(r1, 1e-14) && x2.AlmostEqualRelative(r2, 1e-14) ||
                          x1.AlmostEqualRelative(r2, 1e-14) && x2.AlmostEqualRelative(r1, 1e-14));

            // Verify they really are roots
            AssertComplexEqual(Complex.Zero, c + b * x1 + a * x1 * x1, 1e-14);
            AssertComplexEqual(Complex.Zero, c + b * x2 + a * x2 * x2, 1e-14);
        }
Beispiel #6
0
        public static double Y(double[] coefs, double pX)
        {
            Array.Reverse(coefs);

            var x = Expr.Variable("x");

            var curve = Expr.Parse(new Polynomial(coefs).ToString().Replace(",", ".").Replace("x", "*x"));
            var tang  = curve.Differentiate(x) * x;

            Func <double, double> fx = (curve).Compile("x");

            var xResult = fx(5);

            var xx = FindRoots.OfFunction(fx, -5, 5);

            return(tang.Evaluate(new Dictionary <string, MathNet.Symbolics.FloatingPoint> {
                { "x", pX }
            }).RealValue);
        }
        public double GetPileLengthByBearingCapacity()
        {
            if (m_wantedPileBearing <= 0)
            {
                throw new ArgumentOutOfRangeException("m_wantedPileBearing");
            }
            Dictionary <double, double> pilelengthandbearingforce;

            GetPileCacluateInfo(out pilelengthandbearingforce);
            List <double> points = new List <double>(), values = new List <double>();

            foreach (var keyvalue in pilelengthandbearingforce)
            {
                points.Add(keyvalue.Key);
                values.Add(keyvalue.Value);
            }
            var interpolate = Interpolate.Linear(points, values);

            return(FindRoots.OfFunction(x => interpolate.Interpolate(x) - m_wantedPileBearing, points.Min(), points.Max()));
        }
Beispiel #8
0
        public double Distance(Simplex line)
        {
            var  p                  = line.Edges[0].Item2;
            var  q                  = line.Edges[1].Item2;
            Line line_pq            = t => p + (q - p) * t;
            Func <double, double> f = t => line_pq(t).L2Norm() - 1.0;

            var t_a = FindRoots.OfFunction(f, -3.0 / (p - q).L2Norm(), .0);
            var t_b = FindRoots.OfFunction(f, 1.0, 3.0 / (p - q).L2Norm());

            var a = line_pq(t_a);
            var b = line_pq(t_b);

            var aq = (a - q).L2Norm();
            var ap = (a - p).L2Norm();
            var pb = (p - b).L2Norm();
            var qb = (q - b).L2Norm();

            return(.5 * Math.Log((aq * pb) / (ap * qb)));
        }
        public void MultipleRoots()
        {
            // Roots at -2, 2
            Func <double, double> f1 = x => x * x - 4;

            Assert.AreEqual(0, f1(FindRoots.OfFunction(f1, 0, 5, 1e-14)));
            Assert.AreEqual(-2, FindRoots.OfFunction(f1, -5, -1, 1e-14));
            Assert.AreEqual(2, FindRoots.OfFunction(f1, 1, 4, 1e-14));
            Assert.AreEqual(0, f1(FindRoots.OfFunction(x => - f1(x), 0, 5, 1e-14)));
            Assert.AreEqual(-2, FindRoots.OfFunction(x => - f1(x), -5, -1, 1e-14));
            Assert.AreEqual(2, FindRoots.OfFunction(x => - f1(x), 1, 4, 1e-14));

            // Roots at 3, 4
            Func <double, double> f2 = x => (x - 3) * (x - 4);

            Assert.AreEqual(0, f2(FindRoots.OfFunction(f2, 3.5, 5, 1e-14)), 1e-14);
            Assert.AreEqual(3, FindRoots.OfFunction(f2, -5, 3.5, 1e-14));
            Assert.AreEqual(4, FindRoots.OfFunction(f2, 3.2, 5, 1e-14));
            Assert.AreEqual(3, FindRoots.OfFunction(f2, 2.1, 3.9, 0.001), 0.001);
            Assert.AreEqual(3, FindRoots.OfFunction(f2, 2.1, 3.4, 0.001), 0.001);
        }
        public double Length(String P, String Q)
        {
            var _P = Vector<double>.Build.DenseOfArray(GetPoint(P));
            var _Q = Vector<double>.Build.DenseOfArray(GetPoint(Q));

            Func<double, Vector<double>> line_pq = t => _P + (_Q - _P) * t;
            Func<double, double> f = t => line_pq(t).L2Norm() - 1.0;

            var t_A = FindRoots.OfFunction(f, -3.0 / (_P - _Q).L2Norm(), .0);
            var t_B = FindRoots.OfFunction(f, 1.0, 3.0 / (_P - _Q).L2Norm());

            var _A = line_pq(t_A);
            var _B = line_pq(t_B);

            var aq = (_A - _Q).L2Norm();
            var ap = (_A - _P).L2Norm();
            var pb = (_P - _B).L2Norm();
            var qb = (_Q - _B).L2Norm();

            return .5 * Math.Log((aq * pb) / (ap * qb));
        }
        protected static double Length(double[] P, double[] Q)
        {
            var _P = Vector <double> .Build.DenseOfArray(P);

            var _Q = Vector <double> .Build.DenseOfArray(Q);

            Func <double, Vector <double> > line_pq = t => _P + (_Q - _P) * t;
            Func <double, double>           f       = t => line_pq(t).L2Norm() - 1.0;

            var t_A = FindRoots.OfFunction(f, -3.0 / (_P - _Q).L2Norm(), .0);
            var t_B = FindRoots.OfFunction(f, 1.0, 3.0 / (_P - _Q).L2Norm());

            var _A = line_pq(t_A);
            var _B = line_pq(t_B);

            var aq = (_A - _Q).L2Norm();
            var ap = (_A - _P).L2Norm();
            var pb = (_P - _B).L2Norm();
            var qb = (_Q - _B).L2Norm();

            return(.5 * Math.Log((aq * pb) / (ap * qb)));
        }
Beispiel #12
0
        private void CalculateOptimizeProductionAmount()
        {
            Func <double, double> f = x => A + B * x + C * Math.Pow(x, 2);

            Func <double, double> dtk = x => A / x + B + C * x;

            var dtkFirstDerivative = Derivative.Derive(dtk, 1);

            OptimizeAmount          = Math.Round(FindRoots.OfFunction(dtkFirstDerivative, 1, 500));
            OptimizeProductionCosts = dtk(OptimizeAmount);

            if (OptimizeProductionCosts < SellPrice)
            {
                Func <double, double> g = x => SellPrice * x - (A + B * x + C * Math.Pow(x, 2));
                var gFirstDerivative    = Derivative.Derive(g, 1);
                ProfitAmount = Math.Round(FindRoots.OfFunction(gFirstDerivative, 1, 500));
                Profit       = g(ProfitAmount);
            }
            else
            {
                Profit = double.NaN;
            }
        }
Beispiel #13
0
        private void button1_Click(object sender, EventArgs e)
        {
            Double d = Convert.ToDouble(ac.Text);

            Double c = Convert.ToDouble(bc.Text);

            Double b = Convert.ToDouble(bc.Text);

            Double a = Convert.ToDouble(ac.Text);

            var roots = FindRoots.Cubic(d, c, b, a);

            Complex root1 = roots.Item1;

            Complex root2 = roots.Item2;

            Complex root3 = roots.Item3;

            One.Text = One.Text + " " + root1.Real + " + " + "(" + root1.Imaginary + ")" + " i";

            Two.Text = Two.Text + " " + root2.Real + " + " + "(" + root2.Imaginary + ")" + " i";

            Three.Text = Three.Text + " " + root2.Real + " + " + "(" + root3.Imaginary + ")" + " i";
        }
Beispiel #14
0
 public double[] Roots(Polynomial line, double x1  = Double.NegativeInfinity, double x2 = Double.PositiveInfinity,
                       double absoluteMaximumError = 5e-6) => FindRoots.Polynomial((this - line).Coefficients)
 .Where(c => c.IsReal()).Select(c => c.Real)
 .Where(x => x.CompareTo(x1, absoluteMaximumError) == 1 && x.CompareTo(x2, absoluteMaximumError) <= 0)
 .ToArray();
        /// <summary>
        /// Spawns cubes upon an arc of an ellipse.
        /// </summary>
        /// <param name="n"> The number of cubes. </param>
        /// <param name="center"> The center of the ellipse. </param>
        /// <param name="sectorChordLength"> The length of the arc's chord. </param>
        /// <param name="semiMinorAxisLength"> Half the length of the minor axis. </param>
        /// <param name="sectorAngleDeg"> The angular length of the arc in degrees. </param>
        /// <param name="cubePrefab"> The template for the cubes. </param>
        /// <param name="parent"> The parent of the cubes structure. </param>
        /// <returns> Returns the GameObject containing the cubes, whose parent is 'parent'. </returns>
        /// <remarks> This function is definitely very time-expensive. Use sparingly. </remarks>
        private static GameObject SpawnEllipseCubes(int n, Vector3 center, float sectorChordLength, float semiMinorAxisLength, float sectorAngleDeg, GameObject cubePrefab, Transform parent = null)
        {
            // TODO: Find constraints for every parameter and variable (minimum and maximum values)
            //       Problem: for some combination of input parameters, the FindRoots.OfFunction method fails with an exception:
            //                "ArithmeticException: Function does not accept floating point Not-a-Number values."
            //       Sample parameters: (16,, 12.0f, 6.0f, 90°,,)

            #region Maths

            /*
             * C: center of the ellipse
             * R: sectorChordLength, the length of the chord
             * a: half the length of the major axis of the ellipse
             * b: semiMinorAxisLength, half the length of the minor axis of the ellipse
             * α: sectorAngleDeg, the sector extension in degrees, from (90° - α/2) to (90° + α/2) counterclock-wise
             * n: number of cubes
             *
             *
             * § 1) ELLIPSE'S EQUATIONS
             *
             * ξ(ϑ): ellipse's parametric equations [-180° ≤ ϑ ≤ 180°]
             *     where ϑ is the angle of (ξˣ(ϑ), ξʸ(ϑ)) with the major axis of the ellipse itself
             *                       ___________________________
             *   ξˣ(ϑ) = a b cos(ϑ) √(a² sin²(ϑ) + b² cos²(ϑ))⁻¹
             *                       ___________________________
             *   ξʸ(ϑ) = a b sin(ϑ) √(a² sin²(ϑ) + b² cos²(ϑ))⁻¹
             *
             * A = ξ(90° + α/2)
             * B = ξ(90° - α/2)
             *
             *     __                   _______________________________
             * R = AB = 2 a b sin(α/2) √(a² cos²(α/2) + b² sin²(α/2))⁻¹
             *      _________________________________________                   _______________________
             * a = √(b² R² tan²(α/2)) / (4 b² tan²(α/2) - R²) = (b R tan(α/2)) √(4 b² tan²(α/2) - R²)⁻¹
             *
             *
             * § 2) CUBES PLACEMENT
             *      A _____________________
             * L = ∫(√D[ξˣ(ϑ)]² + D[ξʸ(ϑ)]²)dϑ: length of arc AB
             *    B
             * l = L/n: distance between each cube's center on the arc
             *
             * θᵢ: angle of the iᵗʰ arc segment; arc length to the iᵗʰ arc segment = i l
             * θᵢ = FindRoot[∫(D[ξˣ(ϑ)]² + D[ξʸ(ϑ)]²)dϑ = i l]   😭
             *
             * Pᵢ = ξ(θᵢ): position of the iᵗʰ cube
             *
             *
             * § 3) CUBES' SIDE LENGTH
             * Let Pᵢ and Pⱼ be the positions of two consecutive cubes (j = i + 1) with angles θᵢ and θⱼ.
             * Let Pₖ be a third point placed at the same arc-distance from both Pᵢ and Pⱼ; the angle of Pₖ is θₖ.
             *
             * rₖ: line from C to Pₖ
             * rᵢ: line from C to Pᵢ
             * rⱼ: line from C to Pⱼ
             *
             * M: parametric point on rₖ
             * dᵢ: segment MPᵢ
             * dⱼ: segment MPⱼ
             *
             *
             * M = (mˣ, mʸ) = (mˣ, mˣ tan(θₖ))
             *       ____________________________________
             * dᵢ = √(x(Pᵢ) - mˣ)² + (y(Pᵢ) - mˣ tan(θₖ))²
             *       ____________________________________
             * dⱼ = √(x(Pⱼ) - mˣ)² + (y(Pⱼ) - mˣ tan(θₖ))²
             *
             * ASSERTION
             * dᵢ = dⱼ = d: dᵢ and dⱼ are the semi-diagonals of the two squares
             *
             * (x(Pᵢ) - mˣ)² + (y(Pᵢ) - mˣ tan(θₖ))² = (x(Pⱼ) - mˣ)² + (y(Pⱼ) - mˣ tan(θₖ))²
             * x(Pᵢ)² + (mˣ)² - 2 x(Pᵢ) mˣ + y(Pᵢ)² + (mˣ tan(θₖ))² - 2 y(Pᵢ) mˣ tan(θₖ)  =  x(Pⱼ)² + (mˣ)² - 2 x(Pⱼ) mˣ + y(Pⱼ)² + (mˣ tan(θₖ))² - 2 y(Pⱼ) mˣ tan(θₖ)
             * x(Pᵢ)² - 2 x(Pᵢ) mˣ + y(Pᵢ)² - 2 y(Pᵢ) mˣ tan(θₖ)  =  x(Pⱼ)² - 2 x(Pⱼ) mˣ + y(Pⱼ)² - 2 y(Pⱼ) mˣ tan(θₖ)
             * 2 x(Pⱼ) mˣ + 2 y(Pⱼ) mˣ tan(θₖ) - 2 x(Pᵢ) mˣ - 2 y(Pᵢ) mˣ tan(θₖ)  =  x(Pⱼ)² + y(Pⱼ)² - x(Pᵢ)² - y(Pᵢ)²
             * 2 mˣ (x(Pⱼ) + y(Pⱼ) tan(θₖ) - x(Pᵢ) - y(Pᵢ) tan(θₖ))  =  x(Pⱼ)² + y(Pⱼ)² - x(Pᵢ)² - y(Pᵢ)²
             *
             *              x(Pⱼ)² + y(Pⱼ)² - x(Pᵢ)² - y(Pᵢ)²
             * mˣ = ——————————————————————————————————————————————————
             *       2 (x(Pⱼ) + y(Pⱼ) tan(θₖ) - x(Pᵢ) - y(Pᵢ) tan(θₖ))
             *
             * cube's side length = 2 (d/√2)
             *
             */

            #endregion Maths

            double R = sectorChordLength;
            double b = semiMinorAxisLength;

            #region § 1) ELLIPSE'S EQUATION

            double alphaRad      = Trig.DegreeToRadian(sectorAngleDeg);
            double bTanHalfAlpha = b * Trig.Tan(alphaRad / 2.0);
            double a             = (R * bTanHalfAlpha) / Math.Sqrt(4 * bTanHalfAlpha * bTanHalfAlpha - R * R);

            Func <double, double> EllipseX = t =>
            {
                double sin  = Trig.Sin(t);
                double cos  = Trig.Cos(t);
                double aSin = a * sin;
                double bCos = b * cos;
                return((a * bCos) / Math.Sqrt(aSin * aSin + bCos * bCos));
            };
            Func <double, double> EllipseY = t =>
            {
                double sin  = Trig.Sin(t);
                double cos  = Trig.Cos(t);
                double aSin = a * sin;
                double bCos = b * cos;
                return((b * aSin) / Math.Sqrt(aSin * aSin + bCos * bCos));
            };

            #endregion § 1) ELLIPSE'S EQUATION

            #region § 2) CUBES PLACEMENT

            Func <double, double> DEllipseX = Differentiate.FirstDerivativeFunc(EllipseX);
            Func <double, double> DEllipseY = Differentiate.FirstDerivativeFunc(EllipseY);

            Func <double, double> SqrtOfSumOfSquaredDerivatives = t =>
            {
                double x = DEllipseX(t);
                double y = DEllipseY(t);
                return(Math.Sqrt(x * x + y * y));
            };

            Func <double, double, double> AngleToArcLength = (fromRad, toRad) => Integrate.OnClosedInterval(SqrtOfSumOfSquaredDerivatives, fromRad, toRad);
            Func <double, double>         ArcLengthToAngle = arcLength => FindRoots.OfFunction(toRad => AngleToArcLength((Math.PI - alphaRad) / 2, toRad) - arcLength, 0, Math.PI);

            double L = AngleToArcLength((Math.PI - alphaRad) / 2, (Math.PI + alphaRad) / 2);
            double l = L / (n - 1);

            Func <int, object[]> CalculateCubePositionAndAngle = i =>
            {
                double  angle    = ArcLengthToAngle(i * l);
                Vector2 position = new Vector2((float)EllipseX(angle), (float)EllipseY(angle));
                return(new object[] { position, angle });
            };

            #endregion § 2) CUBES PLACEMENT

            #region § 3) CUBES' SIDE LENGTH

            Vector2[] positions    = new Vector2[n];
            double[]  angles       = new double[n];
            double[]  middleAngles = new double[n - 1];
            for (int i = 0; i < n; ++i)
            {
                object[] res = CalculateCubePositionAndAngle(i);
                positions[i] = (Vector2)res[0];
                angles[i]    = (double)res[1];

                if (i > 0)
                {
                    middleAngles[i - 1] = ArcLengthToAngle((2 * i - 1) * l / 2.0);
                }
            }

            double[]           sideLengths = new double[n - 1];
            Func <int, double> SideLength  = j =>
            {
                double xj   = positions[j].x;
                double yj   = positions[j].y;
                double xi   = positions[j - 1].x;
                double yi   = positions[j - 1].y;
                double tanK = Trig.Tan(middleAngles[j - 1]);
                double mx   = (xj * xj + yj * yj - (xi * xi + yi * yi)) / (2.0 * (xj + yj * tanK - (xi + yi * tanK)));
                return(Math.Sqrt((xi - mx) * (xi - mx) + (yi - mx * tanK) * (yi - mx * tanK)) * (2.0 / Math.Sqrt(2.0)));
            };
            for (int i = 1; i < n; ++i)
            {
                sideLengths[i - 1] = SideLength(i);
            }

            float squareSide = (float)sideLengths.Min();

            #endregion § 3) CUBES' SIDE LENGTH

            // Save parent's current local rotation and scale; it will be re-set later
            Quaternion parentRotation = parent?.localRotation ?? Quaternion.identity;
            Vector3    parentScale    = parent?.localScale ?? Vector3.one;
            if (parent != null)
            {
                parent.localRotation = Quaternion.identity;
                parent.localScale    = Vector3.one;
            }

            GameObject cubesContainer = parent?.gameObject ?? new GameObject();
            cubesContainer.name = $"Ellipse_{n}Cubes";
            cubesContainer.transform.localPosition = center;

            // Create the cubes
            for (int i = 0; i < n; ++i)
            {
                GameObject cube = Instantiate(cubePrefab);
                cube.name = $"Cube{i}";
                cube.SetActive(true); // Awake it now, to let it store the prefab's original scale
                cube.transform.localScale    = new Vector3(squareSide, squareSide, squareSide);
                cube.transform.position      = cubesContainer.transform.position + new Vector3(positions[i].x, 0.0f, positions[i].y);
                cube.transform.localRotation = Quaternion.Euler(0.0f, (float)(90.0 - Trig.RadianToDegree(angles[i])), 0.0f);
                cube.transform.parent        = cubesContainer.transform;
            }
            cubesContainer.transform.localRotation = Quaternion.identity;

            // Re-set parent's original local rotation
            if (parent != null)
            {
                parent.localRotation = parentRotation;
                parent.localScale    = parentScale;
            }

            return(cubesContainer);
        }
        public void NoRoot()
        {
            Func <double, double> f1 = x => x * x + 4;

            Assert.Throws <NonConvergenceException>(() => FindRoots.OfFunction(f1, -5, 5, 1e-14));
        }
Beispiel #17
0
 /// <summary>
 /// Acha o zero da função f(x) usando o metodo de Brent
 /// <param name="func">A função que vai ser zerada. </param>
 /// <param name="limiteInf">O limite inferior de onde o zero está. </param>
 /// <param name="limitSup">O limite superior de onde o zero está. </param>
 /// <param name="precisao">A precissão desejada. </param>
 /// <param name="nInte">O número máximo de iterações. </param>
 /// <returns> x tal que f(x) = 0. </returns>
 /// </summary>
 public double AchaRaizBrenet(Func <double, double> fx, double limiteInf, double limitSup, double precisao = 1e-08, int nInte = 100)
 {
     return(FindRoots.OfFunction(fx, limiteInf, limitSup, precisao, nInte));
 }
 public Complex[] GetRoots(Double[] coefficients)
 {
     return(FindRoots.Polynomial(coefficients));
 }
Beispiel #19
0
    public static float FindRealSolutionSmallestT(double[] coefficients)
    {
        var realSolutions = FindRoots.Polynomial(coefficients).Where(r => r.IsReal() && r.Real > 0).OrderBy(r => r.Real);

        return(realSolutions.Any() ? (float)realSolutions.First().Real : float.PositiveInfinity);
    }
        /// <summary>
        /// Examples of generic function sampling and quantization providers
        /// </summary>
        public override void ExecuteExample()
        {
            MathDisplay.WriteLine("<b>Chebyshev sampling</b>");

            // 1. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of the first kind within interval [0, 10]
            var roots  = FindRoots.ChebychevPolynomialFirstKind(20, 0, 10);
            var result = Generate.Map <double, double>(roots, Function);

            MathDisplay.WriteLine(@"1. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of 
      the first kind within interval [0, 10]");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 2. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of the second kind within interval [0, 10]
            roots  = FindRoots.ChebychevPolynomialSecondKind(20, 0, 10);
            result = Generate.Map <double, double>(roots, Function);
            MathDisplay.WriteLine(@"2. Get 20 samples of f(x) = (x * x) / 2 at the roots of the Chebyshev polynomial of 
      the second kind within interval [0, 10]");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();


            MathDisplay.WriteLine("<b>Equidistant sampling</b>");

            // 1. Get 11 samples of f(x) = (x * x) / 2 equidistant within interval [-5, 5]
            result = Generate.LinearSpacedMap <double>(11, -5, 5, Function);
            MathDisplay.WriteLine(@"1. Get 11 samples of f(x) = (x * x) / 2 equidistant within interval [-5, 5]");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 2. Get 10 samples of f(x) = (x * x) / 2 equidistant starting at x=1 with step = 0.5 and retrieve sample points
            double[] samplePoints = Generate.LinearSpaced(10, 1.0, 5.5);
            result = Generate.Map <double, double>(samplePoints, Function);
            MathDisplay.WriteLine(@"2. Get 10 samples of f(x) = (x * x) / 2 equidistant starting at x=1 with step = 0.5 
      and retrieve sample points");
            MathDisplay.Write(@"Points: ");
            for (var i = 0; i < samplePoints.Length; i++)
            {
                MathDisplay.Write(samplePoints[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.Write(@"Values: ");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 3. Get 10 samples of f(x) = (x * x) / 2 equidistant within period = 10 and period offset = 5
            result = Generate.PeriodicMap <double>(10, Function, 10, 1.0, 10, 5);
            MathDisplay.WriteLine(@"3. Get 10 samples of f(x) = (x * x) / 2 equidistant within period = 10 and period offset = 5");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();



            MathDisplay.WriteLine("<b>Random sampling</b>");

            // 1. Get 10 random samples of f(x) = (x * x) / 2 using continuous uniform distribution on [-10, 10]
            var uniform = new ContinuousUniform(-10, 10);

            result = Generate.RandomMap <double>(10, uniform, Function);
            MathDisplay.WriteLine(@" 1. Get 10 random samples of f(x) = (x * x) / 2 using continuous uniform 
      distribution on [-10, 10]");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 2. Get 10 random samples of f(x) = (x * x) / 2 using Exponential(1) distribution and retrieve sample points
            var exponential = new Exponential(1);

            samplePoints = Generate.Random(10, exponential);
            result       = Generate.Map <double, double>(samplePoints, Function);
            MathDisplay.WriteLine(@"2. Get 10 random samples of f(x) = (x * x) / 2 using Exponential(1) distribution 
      and retrieve sample points");
            MathDisplay.Write(@"Points: ");
            for (var i = 0; i < samplePoints.Length; i++)
            {
                MathDisplay.Write(samplePoints[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.Write(@"Values: ");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
            MathDisplay.WriteLine();

            // 3. Get 10 random samples of f(x, y) = (x * y) / 2 using ChiSquare(10) distribution
            var chiSquare = new ChiSquared(10);

            result = Generate.RandomMap2 <double>(10, chiSquare, TwoDomainFunction);
            MathDisplay.WriteLine(@" 3. Get 10 random samples of f(x, y) = (x * y) / 2 using ChiSquare(10) distribution");
            for (var i = 0; i < result.Length; i++)
            {
                MathDisplay.Write(result[i].ToString("N") + @" ");
            }

            MathDisplay.WriteLine();
        }