Example 2: Solve a Quadratic Programming Problem

The quadratic programming problem is to minimize

x_0^2 + x_1^2 + x_2^2

subject to

x_0 + 2x_1 - x_2 = 4

x_0 - x_1 + x_2 = -2

using System;
using Imsl.Math;

public class QuadraticProgrammingEx2
{
    public static void  Main(String[] args)
    {
        double[,] h = {
            {2, 0, 0}, 
            {0, 2, 0}, 
            {0, 0, 2}
        };
        double[,] aeq = {
            {1, 2, - 1}, 
            {1, - 1, 1}
        };
        double[] beq = new double[]{4, - 2};
        double[] g = new double[]{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   0.285714285714286  
1   1.42857142857143   
2  -0.857142857142857  

         dual
           0           
0   1.14285714285714   
1  -0.571428571428572  


Link to C# source.