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); }
protected override void Given() { _outputVariable = new Variable("Grasp", "Test", typeof(int)); _value = 1; _function = runtime => _value; _calculator = new FunctionCalculator(_outputVariable, _function); var schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>()); _runtime = new GraspRuntime(schema, _calculator, Enumerable.Empty<VariableBinding>()); }
protected override void Given() { _outputVariable1 = new Variable("Grasp", "Test1", typeof(int)); _outputVariable2 = new Variable("Grasp", "Test2", typeof(int)); _value1 = 1; _value2 = 2; _function1 = runtime => _value1; _function2 = runtime => _value2; _calculator1 = new FunctionCalculator(_outputVariable1, _function1); _calculator2 = new FunctionCalculator(_outputVariable2, _function2); _compositeCalculator = new CompositeCalculator(_calculator1, _calculator2); var schema = new GraspSchema(Enumerable.Empty<Variable>(), Enumerable.Empty<Calculation>()); _runtime = new GraspRuntime(schema, _compositeCalculator, Enumerable.Empty<VariableBinding>()); }
/// <summary> /// Set the function from the list according to its name /// </summary> /// <param name="idx">Index of the function name in an array</param> private void SetAFunction(int idx) { _functionCalc = ChooseAFunction(idx); }
protected override void When() { _calculator = new FunctionCalculator(_outputVariable, _function); }