public QuadraticConstraint(IObjectiveFunction objective,
double[,] quadraticTerms, double[] linearTerms = null,
ConstraintType shouldBe = ConstraintType.LesserThanOrEqualTo,
double value = 0, double withinTolerance = 0.0)
{
int n = objective.NumberOfVariables;
if (quadraticTerms == null)
throw new ArgumentNullException("quadraticTerms");
if (quadraticTerms.GetLength(0) != quadraticTerms.GetLength(1))
throw new DimensionMismatchException("quadraticTerms", "Matrix must be square.");
if (quadraticTerms.GetLength(0) != n)
throw new DimensionMismatchException("quadraticTerms",
"Matrix rows must match the number of variables in the objective function.");
if (linearTerms != null)
{
if (linearTerms.Length != n)
throw new DimensionMismatchException("linearTerms",
"The length of the linear terms vector must match the "+
"number of variables in the objective function.");
}
else
{
linearTerms = new double[n];
}
this.QuadraticTerms = quadraticTerms;
this.LinearTerms = linearTerms;
Create(n, this.function, shouldBe, value, this.gradient, withinTolerance);
}