using System; using System.Collections.Generic; using System.Linq; using System.Text; using L = Science.Mathematics.LinearAlgebra; namespace Strang3Ed.Chapter08.Section4 { public class Example02 { public Example02() { } private string result; public string Result { get { return result; } } public void Compute() { L.LinearProgramming obj = new L.LinearProgramming(); double[] a = { -3.0,-1.0,-9.0,-1.0 }; obj.ObjectiveFunctionCoefficient = a; double[] a1 = { 1.0, 0.0, 2.0, 1.0 }; double[] a2 = { 0.0, 1.0, 1.0, -1.0 }; obj.Constraint(a1, ">=", 4.0); obj.Constraint(a2, ">=", 2.0); obj.Compute(); result = obj.Result + "\r\n"; result += "Max=" + Convert.ToString(obj.MaximumOfObjectiveFunction) + "\r\n"; int i = 0; foreach (double k in obj.MaximumAt) { result += "x(" + i + ")=" + k.ToString() + "\r\n"; i++; } } } } /* A finite solution is found. Max=-10 x(0)=0 x(1)=6 x(2)=0 x(3)=4 */