You are on page 1of 1

Name: Kimhok Chheng

NRP:07111850017002

%Exercise1: Diet Optimization with a Minimum cost


clear; close; clc;
f = [0.5;0.2;0.3;0.8];
A = [400 200 150 500
3 2 0 0
2 2 4 4
2 4 1 5];
b = [500;6;10;8];
Aeq=[];
beq=[];
lb=[0;0;0;0];
ub=[inf;inf;inf;inf];
[Food_item,Diet_Min_cost,exitflag]=linprog(f,-A,-b,[],[],lb,ub);
fprintf('Food item1 = %5.2f Time\n',Food_item(1,1));
fprintf('Food item2 = %5.2f Time\n',Food_item(2,1));
fprintf('Food item3 = %5.2f Time\n',Food_item(3,1));
fprintf('Food item4 = %5.2f Time\n',Food_item(4,1));
fprintf('The minimum cost of diet = %5.2f $\n',Diet_Min_cost);

Optimization terminated.
Food item1 = 0.00 Time
Food item2 = 3.00 Time
Food item3 = 1.00 Time
Food item4 = 0.00 Time
The minimum cost of diet = 0.90 $
Published with MATLAB® R2016a

The result of this diet problem shows that to meet your nutrition requirements at a
minimum cost, we should eat 3 times of the food item2, 1 time of the food item3, and no need
to eat food item1 and food item4. The minimum cost for such a diet is 0.9$.

You might also like