Exemplo n.º 1
0
        public static void approx()
        {
            int[]    size = FileHelper.loadSizes(inputSize);
            MyMatrix vector;

            double[,] partial      = FileHelper.loadDataForAprox(gaussPartial);
            double[,] partialOpt   = FileHelper.loadDataForAprox(gaussPartialOpt);
            double[,] seidel       = FileHelper.loadDataForAprox(gaussSeidel);
            double[,] sparse       = FileHelper.loadDataForAprox(gaussSparseEigen);
            double[,] sparseSeidel = FileHelper.loadDataForAprox(gaussSparseSeidelEigen);
            double[] results = new double[5];
            for (int i = 0; i < size.Length; i++)
            {
                Console.WriteLine("\n\n Size : " + size[i] + "\n");
                Console.WriteLine("-------------------------GAUSS PARTIAL BEZ OPTYMALIZACJI-------------------------");
                vector     = Approximation.CountEquation(partial, 3); //Gauss Partial
                results[0] = Approximation.CountVariable(vector, size[i]);
                Console.WriteLine("\nWynik : " + results[0] + "\n");
                Console.WriteLine("-------------------------GAUSS PARTIAL Z OPTYMALIZACJA-------------------------");
                vector     = Approximation.CountEquation(partialOpt, 2); //Gaus Partial Opt
                results[1] = Approximation.CountVariable(vector, size[i]);
                Console.WriteLine("\nWynik : " + results[1] + "\n");
                Console.WriteLine("-------------------------GAUSS ITERACYJNY : SEIDEL-------------------------");
                vector     = Approximation.CountEquation(seidel, 2);  //Gauss Seidel
                results[2] = Approximation.CountVariable(vector, size[i]);
                Console.WriteLine("\nWynik : " + results[2] + "\n");
                Console.WriteLine("-------------------------GAUSS SPARSE LU EIGEN-------------------------");
                vector     = Approximation.CountEquation(sparse, 1);  //SparseLU Eigen
                results[3] = Approximation.CountVariable(vector, size[i]);
                Console.WriteLine("\nWynik : " + results[3] + "\n");
                Console.WriteLine("-------------------------GAUSS SPARSE SEIDEL EIGEN-------------------------");
                vector     = Approximation.CountEquation(sparseSeidel, 1);//Sparse Seidel Eigen
                results[4] = Approximation.CountVariable(vector, size[i]);
                Console.WriteLine("\nWynik : " + results[4] + "\n");
                FileHelper.saveStatsFromApproximations(infoApproxOutput, size[i], results);
                Console.ReadKey();
            }
        }
Exemplo n.º 2
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            Func <double, double> function = null;
            {
                int  funSelection = 0;
                bool isParsable   = false;
                bool isBetween    = false;
                do
                {
                    Console.WriteLine("Wybierz wariant funkcji do całkowania:");
                    Console.WriteLine("(1). f(x) = 4x^4 -2x^3 + 4x^2 -4x +1 ");
                    Console.WriteLine("(2). f(x) = 4sin(2x) ");
                    Console.WriteLine("(3). f(x) = 2|x^3|");
                    isParsable = Int32.TryParse(Console.ReadLine(), out funSelection);
                    isBetween  = funSelection.IsBetween(1, 3);
                } while (!(isParsable && isBetween));
                switch (funSelection)
                {
                case 1:
                    function = Example.Polynomial;
                    break;

                case 2:
                    function = Example.Sinus;
                    break;

                case 3:
                    function = Example.Absolute;
                    break;
                }
            }

            double a, b;
            {
                bool isNumber  = false;
                bool isCorrect = false;
                do
                {
                    Console.WriteLine("Określ przedziały całkowania:");
                    Console.Write("a:");
                    isNumber = double.TryParse(Console.ReadLine(), NumberStyles.Any, CultureInfo.InvariantCulture, out a);
                    Console.Write("b:");
                    isNumber  = double.TryParse(Console.ReadLine(), NumberStyles.Any, CultureInfo.InvariantCulture, out b);
                    isCorrect = a < b;
                } while (!isNumber || !isCorrect);
            }

            int polynomialDegree;
            {
                bool isDegreeCorrect = false;
                do
                {
                    Console.Write("Określ stopień wielomianu aproksymującego: ");
                    isDegreeCorrect = int.TryParse(Console.ReadLine(), out polynomialDegree);
                } while (!isDegreeCorrect);
            }

            ///
            /// oblicanie funkcji aproksymującej
            ///
            HermitePolynomials hermites = new HermitePolynomials();

            double[] factors = new double[polynomialDegree + 1];
            for (int i = 0; i <= polynomialDegree; i++)
            {
                double fun(double x)
                {
                    return(function(x) * hermites[i](x));
                }

                double integral = new Gauss_Hermite(fun, 0.00001).GetResult();
                factors[i] = integral / (Math.Pow(2, i) * MathExtensions.Factorial(i) * Math.Sqrt(Math.PI));
            }
            Approximation         approximationResult  = new Approximation(factors, hermites, polynomialDegree);
            Func <double, double> approximatedFunction = approximationResult.GetResult();
            /// end
            ///

            ChartValues <ObservablePoint> functionPoints             = new ChartValues <ObservablePoint>();
            ChartValues <ObservablePoint> approximatedFunctionPoints = new ChartValues <ObservablePoint>();

            for (double i = a; i <= b; i++)
            {
                functionPoints.Add(new ObservablePoint(i, function(i))); // wypełnianie listy wartościami (x,y)
                approximatedFunctionPoints.Add(new ObservablePoint(i, approximatedFunction(i)));
            }

            MainWindow window = new MainWindow();

            window.Plot.FunctionValues             = functionPoints;
            window.Plot.ApproximatedFunctionValues = approximatedFunctionPoints;
            window.Plot.Update(); // rysowanie wykresu
            window.Show();
        }