Reputation: 47
I was given a problem of using the following recipes to calculate how many gallons of blend could be produced.
1 gallon orange blend: 3 quarts of orange juice, 0.75 quart of pineapple juice, 0.25 quart of mango juice.
1 gallon pineapple blend: 1 quart of orange juice, 2.5 quarts of pineapple juice, 0.5 quart of mango juice.
1 gallon mango blend: 0.5 quart of orange juice, 0.5 quart of pineapple juice, 3 quarts of mango juice.
You are given 7600 gallons of orange juice, 4900 gallons of pineapple juice, and 3500 mango juice
I converted all of the recipe requirements to gallons
Here's my code but it is not giving me a straightforward answer. Why is it giving me odd decimal answers?
clc
clear
A = [.75;.1875;.0625];
B = [.25;.625;.125];
C = [.125;.125;.75];
X = [7600;4900;3500];
OrangeBlend = X./A
PineappleBlend = X./B
MangoBlend = X./C
Upvotes: 0
Views: 387
Reputation: 4269
I think this is meant to be an optimization problem: You want to maximize the amount of blend you make with the available juices you have:
Amount of blend:
max blendorange + blendpineapple + blendmango
with
0.75*blendorange + 0.25*blendpineapple + 0.125*blendmango < 7600;
0.1857*blendorange + 0.625*blendpineapple + 0.125*blendmango < 4900;
0.0625*blendorange + 0.125*blendpineapple + 0.75*blendmango < 3500;
This translates in Matlab in a linprog problem:
f = [-1 -1 -1]'; % because linprog minimizes and we want to maximize
A = [0.75 0.25 0.125;0.1875 0.625 0.125;0.0625 0.125 0.75];
b = [7600;4900;3500];
linprog(f,A,b)
This gives:
ans =
1.0e+003 *
8.0000
4.8000
3.2000
So 8000 gallons of orange, 4800 gallons of pineapple and 3200 gallons of mango...
Funny to notice is that
A*ans
yields 1.0e+003 *
7.6000
4.9000
3.5000
So exactly all the juices are used. This means the problem could just have been solved with:
A\b
because the proportions are exactly so that when maximizing the blend quantity you use up all the juice. Anyway I don't know how the question was asked to you so that's why I didn't go for the linear equation directly.
Hope this helps...
Upvotes: 2