Example 1: Solve a Quadratic Programming Problem

The quadratic programming problem is to minimize

x_0^2 + x_1^2 + x_2^2 + x_3^2 + x_4^2 - 2x_1x_2 - 2x_3x_4 - 2x_0

subject to

x_0 + x_1 + x_2 + x_3 + x_4 = 5

x_2 - 2x_3 - 2x_4 = -3

using System;
using Imsl.Math;

public class QuadraticProgrammingEx1
{
    public static void  Main(String[] args)
    {
        double[,] h = {
            {2, 0, 0, 0, 0}, 
            {0, 2, - 2, 0, 0}, 
            {0, - 2, 2, 0, 0}, 
            {0, 0, 0, 2, - 2}, 
            {0, 0, 0, - 2, 2}
        };
        double[,] aeq = {
            {1, 1, 1, 1, 1},
            {0, 0, 1, - 2, - 2}
        };
        double[] beq = new double[]{5, - 3};
        double[] g = new double[]{- 2, 0, 0, 0, 0};
        
        QuadraticProgramming qp = 
            new QuadraticProgramming(h, g, aeq, beq, null, null);
        
        // Print the solution and its dual
        new PrintMatrix("x").Print(qp.GetSolution());
        new PrintMatrix("dual").Print(qp.GetDualSolution());
    }
}

Output

  x
   0  
0  1  
1  1  
2  1  
3  1  
4  1  

           dual
             0            
0   0                     
1  -1.18329135783152E-32  


Link to C# source.