MATLAB not displaying the required output.

34 Views Asked by At

I am trying to solve a problem by optimizing it using a linear programming algorithm. I am using the algorithm in which I am minimizing the objective function: $$ c^T x$$

subjected to:

$$ a_i^T x \le b_i $$

I am trying to find the best hydrogen tank type and fuel cell for a vehicle. The code I am using is:

% Define the problem data
n = 4; % Number of tank types
m = 5; % Number of fuel cells

% Tank type data
cost_tank = [5000; 4000; 4500; 5500];
weight_tank = [50; 40; 45; 45];
capacity_tank = [300; 200; 250; 350];
durability_tank = [0.9; 0.8; 0.85; 0.95];
safety_tank = [0.8; 0.9; 0.85; 0.95];

% Fuel cell data
capacity_fc = [180; 120; 150; 200; 160];
weight_fc = [30; 25; 35; 40; 20];
durability_fc = [0.7; 0.6; 0.75; 0.8; 0.65];
cost_fc = [8000; 7000; 7500; 6000; 9000];

% Define the decision variables
cvx_begin
variables x(n) y(m)

% Define the objective function
minimize(cost_tank' * x + cost_fc' * y)

% Define the constraints
subject to
    weight_tank' * x + weight_fc' * y <= 200
    capacity_tank' * x + capacity_fc' * y >= 600
    durability_tank' * x + durability_fc' * y >= 0.7
    safety_tank' * x + y >= 0.9
    x >= 0
    y >= 0
cvx_end

% Display the optimal tank type and fuel cell
[optimal_tank_type, ~] = find(x > 0);
[optimal_fc, ~] = find(y > 0);

tank_types = ["Type 1", "Type 2", "Type 3", "Type 4"];
fuel_cells = ["Alkaline Fuel Cell", "Direct Methanol Fuel Cell", "Molten- 
Carbonate Fuel Cell", "Phosphoric Acid Fuel Cell", "Proton Exchange Membrane 
Fuel Cell"];

fprintf("Optimal Tank Type: %s\n", tank_types(optimal_tank_type))
fprintf("Optimal Fuel Cell: %s\n", fuel_cells(optimal_fc))

Now when I run the code in MATLAB I only get the index numbers that is 2 and 2 in the Command Window. What modification can I do in the code above so that it displays the answer like for example Tank Type 3 and Alkaline Fuel Cell?