%Solution to Problem 3.4 in Chapter 3 (Linear Programming). % In this alternative, we do not use the contract amounts specifically % in the program. %Build the constraint matrix: A=zeros(20,12); b=zeros(20,1); Aeq=zeros(3,12); %Contract amounts beq=[10000;8000;8000]; %Contract Amounts Cattle=1:4; Sheep=5:8; Chicken=9:12; Aeq(1,Cattle)=[1 1 1 1]; Aeq(2,Sheep)=[1 1 1 1]; Aeq(3,Chicken)=[1 1 1 1]; %Shortages: I=eye(4); A(1:4,Cattle)=I; A(1:4,Sheep)=I; A(1:4,Chicken)=I; b(1:4)=[6000;10000;5000;5000]; clear I %Vitamins: A(5,Cattle)=[-2 0 -4 2]; A(6,Sheep)=[-2 0 -4 2]; A(7,Chicken)=[-4 -2 -6 0]; A(8,Chicken)=[2 0 4 -2]; %Protein: Temp=[-4 1 -6 -2]; A(9,Cattle)=Temp; A(10,Sheep)=Temp; A(11,Chicken)=Temp; %Calcium A(12,Cattle)=[1 -3 1 1]; A(13,Sheep)=[0 -4 0 0]; A(14,Chicken)=[0 -4 0 0]; %Fat: Temp=[-4 -2 -2 -5]; A(15,Cattle)=Temp; A(16,Sheep)=Temp; A(17,Chicken)=Temp; clear Temp %Fat Max: A(18,Cattle)=[0 -2 -2 1]; A(19,Sheep)=[2 0 0 3]; A(20,Chicken)=[2 0 0 3]; %Delete the max fat: A(19:20,:)=[]; b(19:20)=[]; c=repmat([.2 .12 .24 .12],1,3); lb=zeros(12,1); [f fopt]=linprog(c,A,b,Aeq,beq,lb) %Verify the numbers: TotalCorn=sum(f([1,5,9]))/1000 TotalLime=sum(f([2,6,10]))/1000 TotalSoy=sum(f([3,7,11]))/1000 TotalFish=sum(f([4,8,12]))/1000 TotalCattle=sum(f(Cattle))/1000 TotalSheep=sum(f(Sheep))/1000 TotalChicken=sum(f(Chicken))/1000