예제 #1
0
        private static float[] GenerateX(float a, float b, float step)
        {
            int pointCount = ChebyshevApproximation.CalculateRank(a, b, step);
            var result     = new float[pointCount];

            for (int i = 0; i < pointCount; i++)
            {
                result[i] = a + i * step;
            }
            return(result);
        }
예제 #2
0
        public void Approximate()
        {
            float a       = -2.0f;
            float b       = 2.0f;
            float step    = 0.5f;
            int   rank    = ChebyshevApproximation.CalculateRank(a, b, step);
            var   polynom = ChebyshevApproximation.Approximate(a, b, rank, myFunc);

            List <float> results = new List <float>();
            var          xApprox = GenerateX(a, b, 0.0001f);

            for (float i = a; i <= b; i += 0.0001f)
            {
                float x = ChebyshevApproximation.Squish(i, a, b);
                results.Add(ChebyshevApproximation.Evaluate(polynom, x));
            }
            Assert.That(polynom.Length == rank + 1);
        }
예제 #3
0
        public void CompareTableAndFunc()
        {
            float a       = -2.0f;
            float b       = 2.0f;
            float step    = 0.5f;
            int   rank    = ChebyshevApproximation.CalculateRank(a, b, step);
            var   xValues = GenerateX(a, b, step);
            var   yValues = new float[rank];

            for (int i = 0; i < rank; i++)
            {
                yValues[i] = (float)myFunc(xValues[i]);
            }

            var expectedCoefficients = new Matrix(ChebyshevApproximation.Approximate(a, b, rank - 1, myFunc));

            var actualCoefficients = new Matrix(ChebyshevApproximation.Approximate(xValues, yValues, xValues.Length - 1));

            Assert.That(actualCoefficients.NearEquals(expectedCoefficients, (float)Math.PI + 0.2f), $"Expected: {expectedCoefficients.ToString()}, actual {actualCoefficients.ToString()}");
        }
예제 #4
0
        private void DrawMSE_Func()
        {
            var rank    = ChebyshevApproximation.CalculateRank(a, b, step);
            var xValues = new Libs.Matrix(ChebyshevApproximation.GenerateX(a, b, step));
            var yValues = new Libs.Matrix(new float[rank, 1]);

            for (int j = 0; j < yValues.Height; j++)
            {
                yValues[j, 0] = (float)ApproximatedFunction(xValues[0, j]);
            }

            var coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 1);

            MnkK1Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 2);
            MnkK2Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 3);
            MnkK3Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 4);
            MnkK4Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 5);
            MnkK5Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 6);
            MnkK6Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 7);
            MnkK7Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 8);
            MnkK8Plotter.ItemsSource = GeneratePoints(coefs);

            coefs = MeanSquaredErrorApproximation.Approximate(xValues, yValues, 9);
            MnkK9Plotter.ItemsSource = GeneratePoints(coefs);
        }