Create and Solve Maximization Problem
Create a linear programming problem for maximization. The problem has two positive variables and three linear inequality constraints.
prob = optimproblem('ObjectiveSense','max');
Create positive variables. Include an objective function in the problem.
x = optimvar('x',2,1,'LowerBound',0); prob.Objective = x(1) + 2*x(2);
Create linear inequality constraints in the problem.
cons1 = x(1) + 5*x(2) <= 100; cons2 = x(1) + x(2) <= 40; cons3 = 2*x(1) + x(2)/2 <= 60; prob.Constraints.cons1 = cons1; prob.Constraints.cons2 = cons2; prob.Constraints.cons3 = cons3;
Review the problem.
showproblem(prob)
OptimizationProblem : max : x(1, 1) + 2*x(2, 1) subject to cons1: x(1, 1) + 5*x(2, 1) <= 100 subject to cons2: x(1, 1) + x(2, 1) <= 40 subject to cons3: 2*x(1, 1) + 0.5*x(2, 1) <= 60 variable bounds: 0 <= x(1, 1) 0 <= x(2, 1)
Solve the problem.
sol = solve(prob); sol.x
Optimal solution found. ans = 25.0000 15.0000