Initializing help system before first use

object.extractQuadratic

object.extractQuadratic


Purpose

Returns the variables and coefficients of the quadratic part of any expression.


Synopsis
vars1, vars2, coef = a.extractQuadratic()
Arguments
An expression or variable.
vars1 
A list containing the first variables of each bilinear term composing the quadratic expression in a.
vars2 
A list containing the second variables of each bilinear term of the quadratic expression in a.
coef 
A list containing the corresponding coefficients in the quadratic expression.
Example
The following code snippets show what is the expected result of applying extractQuadratic:
import xpress as xp

x = xp.var()
y = xp.var()
z = xp.var()

a = x + 2*y + x*y + 8 * x**2
b = 3*x**2 + z + 4
c = y**2 + x**2 - 6*x*y
d = x**5 - 7*x*y - 4*x*y*z  # nonlinear expression
e = x*y + y*x  # note: same bilinear term added twice. This is compressed to 2*x*y

print (a.extractQuadratic())  # will print "([C1, C1], [C2,C1], [1,8])"
assert (a.extractQuadratic() == ([x,x], [y,x], [1,8]))

print (b.extractQuadratic())  # will print "([C1], [C1], [3])"
print (c.extractQuadratic())  # will print "([C2, C1], [C2, C1], [1, 1])"
print (d.extractQuadratic())  # will print "([C1], [C2], [-7])"
print (e.extractQuadratic())  # will print "([C1], [C2], [2])"
Further information
1. Similar to object.extractLinear, this operator returns variable objects, not indices, in the vars portion of the output tuple. To obtain indices, use the problem.getIndex function. Printing these lists will show the name of the associated variables, as determined by the user when creating the variable with the name argument or, if name is not provided, it will show the name as determined by the Optimizer's library (default variable names are "C"+index). See also the Modelling chapter.
2. This operator is most useful only for quadratic expressions with more than one element. For nonlinear, non-quadratic expressions, the function attempts to extract as much quadratic information it can, but will not be able to detect quadratic/bilinear expressions apart from the most obvious cases. For example, for the expression x**4 + xp.sqrt(y**4), which contains the quadratic term y**2, the function will return ([],[]).

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.