Beispiel #1
0
        public void SolveWithGaussSeidel_Test()
        {
            Matrix inputMatrix = new Matrix(new double[3, 3]
            {
                { 10, -4, -2 },
                { -4, 10, -4 },
                { -6, -2, 12 }
            });

            Vector rightSideVector = new Vector(new double[3]
            {
                2,
                3,
                1
            });
            Vector startValue = new Vector(new double[3] {
                0, 0, 0
            });


            LGS    lgs    = new LGS(inputMatrix, rightSideVector);
            Vector result = lgs.Solve(Enums.ESolveAlgorithm.eGaußSeidel, startValue);

            Vector expected = new Vector(new double[3] {
                0.598, 0.741, 0.506
            });

            Assert.AreEqual(expected, result);
        }
Beispiel #2
0
        private void Grid_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                Clients cl = LGS.GetCurrentID();
                SaveCLID.CLID = cl.id_user;

                id.Content = cl.id_user;

                Model1 db = new Model1();

                var inprocess = (from t in db.Orders
                                 where t.client == SaveCLID.CLID && t.order_status == 2
                                 select t).Count();
                var readyy = (from t in db.Orders
                              where t.client == SaveCLID.CLID && t.order_status == 4
                              select t).Count();

                now.Content   = inprocess;
                ready.Content = readyy;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public static Function CreateRegression(List <Point> points, int degreeOfPolynominal)
        {
            if (degreeOfPolynominal < 1)
            {
                throw new ArgumentException("Degree of polynominal must be at least 1");
            }

            Matrix regressionMatrix = CreateRegressionMatrix(points, degreeOfPolynominal + 1);
            Vector regressionVector = CreateRegressionVector(points, degreeOfPolynominal + 1);

            Parser parser = new Parser();

            LGS    lgs      = new LGS(regressionMatrix, regressionVector);
            string function = CreateRegressionFunction(lgs.Solve(Enums.ESolveAlgorithm.eGaussianElimination), degreeOfPolynominal + 1);

            return(parser.ParseFunction(function));
        }
Beispiel #4
0
        public void SolveWithGaussianElimination_Test()
        {
            Matrix m = new Matrix(new double[4, 4] {
                { 1, 1, 1, 1 }, { 1, 1, -1, -1 }, { 1, -1, 1, 1 }, { 1, -1, -1, 1 }
            });
            Vector v = new Vector(new double[4] {
                0, 1, 3, -1
            });

            LGS    lgs    = new LGS(m, v);
            Vector result = lgs.Solve(Enums.ESolveAlgorithm.eGaussianElimination);

            Vector expected = new Vector(new double[6] {
                1, -2, 3, 4, 2, -1
            });

            Assert.AreEqual(expected, result);
        }
Beispiel #5
0
        public void SolveWithJacobiMethod_Test()
        {
            Matrix inputMatrix = new Matrix(new double[3, 3]
            {
                { 10, -4, -2 },
                { -4, 10, -4 },
                { -6, -2, 12 }
            });

            Vector rightSideVector = new Vector(new double[3]
            {
                2,
                3,
                1
            });

            Vector startValue = new Vector(new double[3]
            {
                0,
                0,
                0
            });

            string info;
            LGS    lgs    = new LGS(inputMatrix, rightSideVector);
            Vector actual = lgs.SolveLGSJacobi(startValue, 100, out info);

            if (!string.IsNullOrEmpty(info))
            {
                File.WriteAllText(@"C:\Users\User\Documents\Berufsschule\2. Lehrjahr\LF 8\Iterative Lösungsverfahren\Jacobi_Second_Diagonal.csv", info);
            }

            actual.Round(3);

            Vector expected = new Vector(new double[3]
            {
                0.598,
                0.741,
                0.506
            });

            Assert.IsFalse(false);
        }
Beispiel #6
0
        public void Jacobi_First_Diagonal_Test()
        {
            Matrix inputMatrix = new Matrix(new double[3, 3]
            {
                { 12, 3, -5 },
                { 1, 5, 3 },
                { 3, 7, 13 }
            });

            Vector rightSideVector = new Vector(new double[3]
            {
                1,
                28,
                76
            });

            Vector startValue = new Vector(new double[3]
            {
                0,
                0,
                0
            });

            string info;
            LGS    lgs    = new LGS(inputMatrix, rightSideVector);
            Vector actual = lgs.SolveLGSJacobi(startValue, 100, out info);

            if (!string.IsNullOrEmpty(info))
            {
                File.WriteAllText(@"C:\Users\User\Documents\Berufsschule\2. Lehrjahr\LF 8\Iterative Lösungsverfahren\Jacobi_First_Diagonal.csv", info);
            }

            actual.Round(3);

            Vector expected = new Vector(new double[3]
            {
                0.598,
                0.741,
                0.506
            });

            Assert.IsTrue(true);
        }
Beispiel #7
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     if (Auth.authC(username.Text, password.Password) == true)
     {
         LGS.CurrentID(username.Text, password.Password);
         Clients cl = LGS.GetCurrentID();
         SaveCLID.CLID = cl.id_user;
         if (cl.block == 1)
         {
             MessageBox.Show("Клиент заблокирован!");
         }
         else if (cl.block == 0)
         {
             ClientMain ms = new ClientMain();
             this.Close();
             ms.Show();
         }
     }
     else if (Auth.authM(username.Text, password.Password) == true)
     {
         LGS.MasterID(username.Text, password.Password);
         MasterMain ms = new MasterMain();
         this.Close();
         ms.Show();
     }
     else if (Auth.authA(username.Text, password.Password) == true)
     {
         AdminMain ms = new AdminMain();
         this.Close();
         ms.Show();
     }
     else if (Auth.authMan(username.Text, password.Password) == true)
     {
         ManagerMain ms = new ManagerMain();
         this.Close();
         ms.Show();
     }
     else
     {
         MessageBox.Show("Логин или пароль неверны!");
     }
 }
Beispiel #8
0
        private void Plot()
        {
            //Make asynchronous
            List <double> hList = CalculateH();
            List <double> gList = CalculateG(hList);

            Math_Collection.LinearAlgebra.Matrices.Matrix m = CreateSplineMatrix(hList);

            double[] gListAsArray = gList.ToArray();
            LGS      lgs          = new LGS(m, new Math_Collection.LinearAlgebra.Vectors.Vector(gListAsArray));

            //Make asynchronous
            Math_Collection.LinearAlgebra.Vectors.Vector outcome = lgs.Solve(LGS.SolveAlgorithm.Gauß);

            string sOutcome = outcome.ToString();

            List <double> bList = CalculateB(outcome, hList);
            List <double> dList = CalculateD(outcome, hList);

            SolveSplineFunctions(CreateSplineFunctions(bList, outcome, dList));
        }
        public MasterMain()
        {
            Masters mas = LGS.GetMasterID();

            SaveMASID.MASID = mas.id_master;

            InitializeComponent();
            Model1 db    = new Model1();
            var    count = (from t in db.Orders
                            where t.client == SaveMASID.MASID && t.order_status == 1
                            select t).Count();
            var inprocess = (from t in db.Orders
                             where t.order_status == 2 && t.client == SaveMASID.MASID
                             select t).Count();
            var readyy = (from t in db.Orders
                          where t.order_status == 4 && t.client == SaveMASID.MASID
                          select t).Count();

            all.Content   = count;
            now.Content   = inprocess;
            ready.Content = readyy;
        }
Beispiel #10
0
        /// <summary>
        /// Calculates all polynominal parts of the spline
        /// </summary>
        /// <returns>A List of Functions that represents all polynominals</returns>
        /// <seealso cref="http://www.tm-mathe.de/Themen/html/funnatsplines.html"/>
        private List <Function> CalculateSplineParts()
        {
            if (_sourcePoints != null && _sourcePoints.Count < 3)
            {
                return(null);
            }

            // 3.Degree Polynomial := f(x) = a + bx + cx^2 + dx^3
            // f'(x) = b + 2cx + 3dx^2
            // f''(x) = 2c + 6dx

            Parser parser = new Parser();

            double[] xs = _sourcePoints.Keys.ToArray();
            double[] ys = _sourcePoints.Values.ToArray();

            #region Calculate Help Variable hi and gi

            double[] hi = CalculateH(xs);

            double[] gi = CalcualteG(ys, hi);

            #endregion

            #region Calculate all c's

            Matrix coefficientMatrix = GetCoefficientMatrix(hi);
            Math_Collection.LinearAlgebra.Vectors.Vector coefficientVector = GetCoefficientVector(gi);
            LGS lgs = new LGS(coefficientMatrix, coefficientVector);

            Math_Collection.LinearAlgebra.Vectors.Vector resultFromLGS = lgs.Solve(Math_Collection.Enums.ESolveAlgorithm.eGaussianElimination);

            double[] ci = new double[_amountOfSplineParts + 2];
            for (int i = 2; i <= _amountOfSplineParts + 1; i++)
            {
                ci[i] = resultFromLGS[i - 1];
            }

            #endregion

            #region Calculates all a values

            // a's = yi-1
            double[] ai = new double[_amountOfSplineParts + 1];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                ai[i] = ys[i - 1];
            }

            #endregion

            #region Calculate all b's

            // bi = (yi - yi-1) / hi - (hi / 3) * (2*ci + ci+1)

            double[] bi = new double[_amountOfSplineParts + 1];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                bi[i] = ((ys[i] - ys[i - 1]) / hi[i]) - (hi[i] / 3) * (2 * ci[i] + ci[i + 1]);
            }

            #endregion

            #region Calculate all d's

            // di = (ci+1 - ci) / 3 * hi

            double[] di = new double[_amountOfSplineParts + 1];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                di[i] = (ci[i + 1] - ci[i]) / (3 * hi[i]);
            }

            #endregion

            #region Generate all Functions

            Function[] functionParts = new Function[_amountOfSplineParts];
            for (int i = 1; i <= _amountOfSplineParts; i++)
            {
                string f = ai[i] + "+" + bi[i] + "*x+" + ci[i] + "*x^2+" + di[i] + "*x^3";
                functionParts[i - 1] = parser.ParseFunction(f);
            }

            #endregion

            return(functionParts.ToList());
        }
Beispiel #11
0
        /// <summary>
        /// Berechnet die Regression für die gegebenen Punkte
        /// </summary>
        /// <param name="?"></param>
        /// <param name="degreeOfPolynominal"></param>
        /// <returns></returns>
        public static Function CalculateRegression(List <Point> points, int degreeOfPolynominal = 1)
        {
            if (points == null || points.Count < 2)
            {
                return(null);
            }

            Matrix inputMatrix = new Matrix(new double[degreeOfPolynominal + 1, degreeOfPolynominal + 1]);

            Math_Collection.LinearAlgebra.Vectors.Vector outputVector =
                new Math_Collection.LinearAlgebra.Vectors.Vector(new double[degreeOfPolynominal + 1]);

            int maxPower    = degreeOfPolynominal * 2;
            int actualPower = maxPower;

            // Input Matrix aufbauen
            for (int i = 0; i < inputMatrix.RowCount; i++)
            {
                for (int k = 0; k < inputMatrix.ColumnCount; k++)
                {
                    actualPower       = maxPower - (i + k);
                    inputMatrix[i, k] = SumXValues(points, actualPower);
                }
            }

            maxPower = degreeOfPolynominal;
            // Output Vector aufbauen
            for (int m = 0; m < outputVector.Size; m++)
            {
                outputVector[m] = SumXYValues(points, maxPower);
                maxPower--;
            }

            // LGS Lösen
            LGS lgs = new LGS(inputMatrix, outputVector);

            Math_Collection.LinearAlgebra.Vectors.Vector resultVector = lgs.Solve();

            // Function aufbauen
            // ax^1 + b; ax^2+bx^1+c
            string functionString = "";

            maxPower = degreeOfPolynominal;
            for (int o = 0; o <= degreeOfPolynominal; o++)
            {
                if (o != degreeOfPolynominal)
                {
                    functionString += string.Format(resultVector[o] + "*x^{0}+", maxPower);
                }
                else
                {
                    functionString += resultVector[o];
                }

                maxPower--;
            }
            functionString = functionString.Replace(",", ".");

            Parser parser = new Parser();

            return(parser.ParseFunction(functionString));
        }