linear programing given demands, capacity and table of input i which pass through section j in matlab

To solve a linear programming problem in MATLAB, you can use the linprog function. Here's an example of how to use it given demands, capacity, and a table of input that passes through a section:

Let's assume you have the following problem:

  • You have m products and n sections.
  • The demand for each product is given in a vector demand of size m x 1.
  • The capacity of each section is given in a vector capacity of size n x 1.
  • The input matrix input_matrix of size m x n represents the amount of input required for each product to pass through each section.

You want to minimize the total cost of production, which is represented by a cost vector cost of size m x 1. The decision variables are the amounts of each product to produce, which are represented by a vector x of size m x 1.

Here's the MATLAB code to solve this problem:

main.m
% Define the demand, capacity, input matrix, and cost
demand = [100; 200; 300];  % Demand for each product
capacity = [500; 600; 700];  % Capacity of each section
input_matrix = [0.5 0.3 0.2; 0.4 0.5 0.1; 0.6 0.2 0.2];  % Input matrix
cost = [10; 20; 30];  % Cost of each product

% Define the number of products and sections
m = length(demand);
n = length(capacity);

% Define the coefficients of the objective function
f = cost;

% Define the coefficients of the inequality constraints
A = [input_matrix'; -eye(m)];  % Constraints: input_matrix * x <= capacity and x >= 0
b = [capacity; zeros(m, 1)];

% Define the coefficients of the equality constraints
Aeq = ones(1, m);  % Constraint: sum(x) == sum(demand)
beq = sum(demand);

% Solve the linear programming problem
[x, fval] = linprog(f, A, b, Aeq, beq);

% Print the solution
fprintf('Optimal production amounts: \n');
disp(x);
fprintf('Minimum cost: %f\n', fval);
923 chars
29 lines

In this code, we first define the input parameters: demand, capacity, input_matrix, and cost. We then define the coefficients of the objective function f, the inequality constraints A and b, and the equality constraints Aeq and beq. Finally, we solve the linear programming problem using the linprog function and print the solution.

gistlibby LogSnag