Determine how much kilogram of each food item the person should consume so as to have maximum intake of vitamins by using appropriate built in function present in MATLAB
2 views (last 30 days)
Show older comments
According to a dietician, a person should consume exactly 200 gm of carbohydrates,at least 175 gm of proteins and at most 150 gm of fats in a meal. The dietician also recommends to have as much amount of vitamins as possible. The three food items that the person eats has 80, 65 and 30 gm of carbohydrates per kilogram of food item. The same food items contain 10, 12, 23 gm of proteins in each kilogram. Per kilogram of the same food items comprise of 32, 56 and 42 gm of fats. Vitamins contained in per kilogram of the same food items are 70, 37 and 58 gm.
Determine how much kilogram of each food item the person should consume so as to have maximum intake of vitamins by using appropriate built in function present in MATLAB
2 Comments
Walter Roberson
on 3 Sep 2023
Matrix methods cannot deal with the inequalities -- at least 175 gm of proteins, and at most 150 gm of fats . You need some kind of optimization to deal with those.
Answers (1)
Abdul
on 19 Oct 2022
Problem based approach
%% In the current problem, x1 , X2 and x3 are the three decision variables
x = optimvar('x',3,'LowerBound', [0 0 0],'UpperBound', [inf inf inf]);
%% In the current problem, objective function is Maximize Z = 0.070X1 +0.037X2 + 0.058X3
obj = (0.070*x(1) + 0.037 * x(2) + 0.058 * x(3));
%% In the current problem, constraints are: 0.080X1 + 0.065X2 +0.030X3 <=0.200 and 0.010X1 +0.012X2+ 0.023X3 <=0.175
% and 0.032X1 + 0.056X2 + 0.042X3 <=0.150
A = 0.080*x(1) + 0.065*x(2) + 0.030*x(3) <= 0.200;
B = 0.010*x(1) + 0.012*x(2) + 0.023*x(3) <= 0.175;
C = 0.032*x(1) + 0.056*x(2) + 0.042*x(3) <=0.150;
prob = optimproblem('Objective',obj,'ObjectiveSense','maximize');
prob.Constraints.con_1 = A;
prob.Constraints.con_2 = B;
prob.Constraints.con_3 = C;
x0.x = [0 0 0];
[sol,fval,exitflag,output] = solve(prob,x0)
Solver Based approach
%%linprog solves the maximization linear programming problems;
%[x fval] = linprog(f,A,b,Aeq,beq,lb,ub)
f = [0.070 0.037 0.058];A = [0.080 0.065 0.030;0.010 0.012 0.023;0.032 0.056 0.042];b = [0.200;0.175;0.150];
Aeq = [];Beq = [];
lb = [0 0 0]; ub = [inf inf inf];
[x fval] = linprog(-f,A,b,Aeq,Beq,lb,ub)
Output x = 1.6250 0 2.3333
fval = 0.2491
0 Comments
See Also
Categories
Find more on Deep Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!