prog = MathematicalProgram()
# x is a symbolic variable
x = prog.NewContinuousVariables(2)
# numerical, pass in the coefficients:
# x'Qx + b'x + c
prog.AddQuadraticCost(Q, b, c, x)
# symbolic:
prog.AddCost(x.dot(x))
prog.AddQuadraticCost(x.dot(x))
# autodiff:
def my_cost(x):
return x.dot(x)
prog.AddCost(my_cost, x)
# Adding autodiff costs/constraints => Solve(prog) will
# pick a nonlinear optimization solver