TP Ota
TP Ota
Minimize ½ xT Q x + cT x
Subject to : Ax £ b
Where :
• Q is a symmetric matrix (for the quadratic part),
• c is a vector (for the linear part),
• A is a matrix defining the linear inequality or equality constraints,
• b is a vector of bounds for the constraints, and
• x is the vector of decision variables you're optimizing.
Example Problem:
Minimize ½ xT Q x + cT x
Subject to : x1+x2 £ 1
-x1+x2 £ 1
Matlab Code :
Additional Practice:
1. Objective function:
o The quadratic part is represented by the matrix Q. For example, if you want to
minimize ½ xTQx+cTx, you use Q = [2 0; 0 2] and c = [-2; -5].
2. Constraints:
o The constraints Ax≤b are defined using matrices A and vector b. Here, A
= [1 1; -1 1] represents two inequality constraints, and b = [1; 1] defines the
bounds on these inequalities.
3. Function quadprog:
o quadprog(Q, c, A, b, [], [], [], [], options) solves the quadratic programming problem.
The empty vectors [] indicate that we have no equality constraints in this case.
o The function returns x, the vector of optimal decision variables, and fval, the
value of the objective function at the optimal solution.
4. Display the solution :
o The disp commands display the optimal values of x and the objective function
at the optimal solution.
When you run this code, MATLAB will solve the problem and output the optimal values for x1
and x2, along with the value of the objective function at the solution.
Output Example:
Optimal solution:
1.0000
0.0000
Key Notes:
• If you have equality constraints, use the Aeq and beq parameters in quadprog:
• You can also handle non-linear constraints using optimization toolboxes like fmincon,
but quadprog is specifically for quadratic programs with linear constraints.