QuadraticObjectiveFunction Class 
Namespace: Accord.Math.Optimization
The QuadraticObjectiveFunction type exposes the following members.
Name  Description  

QuadraticObjectiveFunction(ExpressionFuncDouble) 
Creates a new objective function specified through a string.
 
QuadraticObjectiveFunction(String) 
Creates a new objective function specified through a string.
 
QuadraticObjectiveFunction(String, CultureInfo) 
Creates a new objective function specified through a string.
 
QuadraticObjectiveFunction(Double, Double, String) 
Creates a new objective function specified through a string.

Name  Description  

ConstantTerm 
Gets the constant term in the quadratic function.
 
Function 
Gets the objective function.
(Inherited from NonlinearObjectiveFunction.)  
Gradient 
Gets the gradient of the objective function.
(Inherited from NonlinearObjectiveFunction.)  
Indices 
Gets the index of each input variable in the function.
(Inherited from NonlinearObjectiveFunction.)  
InnerIndices 
Gets the index of each input variable in the function.
(Inherited from NonlinearObjectiveFunction.)  
InnerVariables 
Gets the name of each input variable.
(Inherited from NonlinearObjectiveFunction.)  
LinearTerms 
Gets the vector of linear terms of the quadratic function.
 
NumberOfVariables 
Gets the number of input variables for the function.
(Inherited from NonlinearObjectiveFunction.)  
QuadraticTerms 
Gets the quadratic terms of the quadratic function.
 
Variables 
Gets the name of each input variable.
(Inherited from NonlinearObjectiveFunction.) 
Name  Description  

Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
ToString 
Returns a String that represents this instance.
(Overrides ObjectToString.)  
TryParse(String, QuadraticObjectiveFunction) 
Attempts to create a QuadraticObjectiveFunction
from a String representation.
 
TryParse(String, CultureInfo, QuadraticObjectiveFunction) 
Attempts to create a QuadraticObjectiveFunction
from a String representation.

Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
IsEqual  Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices. (Defined by Matrix.)  
ToT  Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)  
ToT  Overloaded.
Converts an object into another type, irrespective of whether
the conversion can be done at compile time or not. This can be
used to convert generic types to numeric types during runtime.
(Defined by Matrix.) 
In mathematics, a quadratic function, a quadratic polynomial, a polynomial of degree 2, or simply a quadratic, is a polynomial function in one or more variables in which the highestdegree term is of the second degree. For example, a quadratic function in three variables x, y, and z contains exclusively terms x², y², z², xy, xz, yz, x, y, z, and a constant:
f(x,y,z) = ax² + by² +cz² + dxy + exz + fyz + gx + hy + iz + j
Please note that the function's constructor expects the function expression to be given on this form. Scalar values must be located on the left of the variables, and no term should be duplicated in the quadratic expression. Please take a look on the examples section of this page for some examples of expected functions.
References:
Examples of valid quadratic functions are:
var f1 = new QuadraticObjectiveFunction("x² + 1"); var f2 = new QuadraticObjectiveFunction("x*y + y*z"); var f3 = new QuadraticObjectiveFunction("2x² + xy  y²  10xz + z²"); var f4 = new QuadraticObjectiveFunction("2x² + xy  y² + 5y");
It is also possible to specify quadratic functions using lambda expressions. In this case, it is first necessary to create some dummy symbol variables to act as placeholders in the quadratic expressions. Their value is not important, as they will only be used to parse the form of the expression, not its value.
// Declare symbol variables double x = 0, y = 0, z = 0; var g1 = new QuadraticObjectiveFunction(() => x * x + 1); var g2 = new QuadraticObjectiveFunction(() => x * y + y * z); var g3 = new QuadraticObjectiveFunction(() => 2 * x * x + x * y  y * y  10 * x * z + z * z); var g4 = new QuadraticObjectiveFunction(() => 2 * x * x + x * y  y * y + 5 * y);
After those functions are created, you can either query their values using
f1.Function(new [] { 5.0 }); // x*x+1 = x² + 1 = 25 + 1 = 26
Or you can pass it to a quadratic optimization method such as GoldfarbIdnani to explore its minimum or maximal points:
// Declare symbol variables double x = 0, y = 0, z = 0; // Create the function to be optimized var f = new QuadraticObjectiveFunction(() => x * x  2 * x * y + 3 * y * y + z * z  4 * x  5 * y  z); // Create some constraints for the solution var constraints = new List<LinearConstraint>(); constraints.Add(new LinearConstraint(f, () => 6 * x  7 * y <= 8)); constraints.Add(new LinearConstraint(f, () => 9 * x + 1 * y <= 11)); constraints.Add(new LinearConstraint(f, () => 9 * x  y <= 11)); constraints.Add(new LinearConstraint(f, () => z  y == 12)); // Create the Quadratic Programming solver GoldfarbIdnani solver = new GoldfarbIdnani(f, constraints); // Minimize the function bool success = solver.Minimize(); double value = solver.Value; double[] solutions = solver.Solution;