public void GenerateFunction() { // Sort all the points this.FunctionPoints = this.FunctionPoints.OrderBy(a => a.X).ToList(); // Get the coefficient matrix var coefMtrx = GenerateCoefficientMatrix(); // Calculate the determinant of the coefficient matrix double determinant = FunctionCalculator.Determinant(coefMtrx); List <double> yValues = this.FunctionPoints.Select(a => a.Y).ToList(); List <double> valuesOfCoef = new List <double>(); for (int col = 0; col < this.FunctionPoints.Count; col++) { double[,] newMatrix = FunctionCalculator.ReplaceCol((double[, ])coefMtrx.Clone(), yValues, col); double newDeterminant = FunctionCalculator.Determinant(newMatrix); valuesOfCoef.Add(newDeterminant / determinant); } // Get function tree TreeNode generatedTree = FunctionCalculator.GenerateFumcTreeFromCoefficients(valuesOfCoef); // Create function Function newFunction = new Function(generatedTree); // Add Function to the rest this.Window.Controller.AddFunction(newFunction); // Draw the new function this.Painter.DrawFunction(newFunction); }