%problem 172.
%
%In this optimization problem, the student is given a function F and a set of
%inequalities. The student is asked to enter
%
%N=(number of slack variables which must be added), and
%M=(maximum number of basic solutions there could be).
%
%These are checked and then explained. The augmented matrix A for the problem
%has been entered for the student, who must find and record all non-negative
%solutions.
%The student is then required to record the maximum value of the function F
%and the vertex at which it occurs. The problem ends, but to help the student
%with evaluating the value of F at any point, a matrix C has been entered such
%that entering
%
% F=X*C
%
%for any user-defined 1*3 vector will calculate the value of F at X.
clear variables
global undo;
global hintnumber
global noprint;
global err;
err=0;
noprint=0;
hintnumber=172;
N=0;
M=0;
r='nothing'; %this prevents Matlab error on first pass of while loop
A=[1 1 1 0 0 10;-1 2 -1 1 0 8;2 2 -4 0 1 14]; %augmented matrix pre-entered for user.
C=[14;16;15];
clc
sprintf('%s\n\n%s\n\n%s\n\n%s\n\n%s\n\n%s\n\n%s\n\n\n%s \n\n%s','Problem 172.','In this problem you will find the maximum value of',' F(X1,X2,X3) = 14 X1 + 16 X2 + 15 X3','subject to the constraints:',' X1 + X2 + X3 = 10',' -X1 + 2 X2 - X3 <= 8',' 2 X1 + 2 X2 - 4 X3 <= 14',' X1 >= 0, X2 >= 0, X3 >= 0.','press RETURN for more')
input(' '); %wait for return
sprintf('%s\n%s\n\n%s\n%s\n\n%s','How many slack variables must be added ?','Enter the number as N= ... ','What is the maximum number of basic solutions there could be ?','Enter the number as M= ...','Enter "discuss" to have your answers checked')
while(strcmp(r,'stop')==0) %outer loop
r=input('problem 172>>','s');
if (strcmp(r,'stop')==1)
return
end
if (findstr(r,'discuss')>=1)
if (N==2 & M==10)
clc
sprintf('%s\n\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s','Correct !',' N=2. (note that there is no need to add a slack variable for an equality)',' M=10. There are',' 5',' C = 10',' 3','possible basic solutions, as there are 5 variables and 3 equations','(and so 3 pivots)','press RETURN for more')
else
clc
sprintf('%s\n\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s','One or both are incorrect:','N=2. (note that there is no need to add a slack variable for an equality)','M=10. There are',' 5',' C = 10',' 3','possible basic solutions, as there are 5 variables and 3 equations','(and so 3 pivots)','press RETURN for more')
end
input(' '); %wait for return
clc
sprintf('%s\n%s\n\n%s\n%s','The augmented matrix for this problem, A, has already been entered for you.','Find and record all non-negative solutions.','Enter "discuss" when you have done this, or "stop" to leave the problem.','(remember that you can print A on the screen just by entering "A")')
while(strcmp(r,'stop')==0) %inner while loop begin
r=input('problem 172>>','s');
if (strcmp(r,'stop')==1)
return
end
if (findstr(r,'discuss')>=1)
clc
sprintf('%s\n%s\n\n%s\n%s\n\n%s\n\n%s\n\n%s\n\n%s\n%s\n\n%s\n\n%s','Record the maximum value of F and the vertex at which','it occurs as your answer to this question.','To help you with this task, Matlab will calculate F for you','if you enter the values X1, X2, X3 in a row vector called X,',' ie: X=[X1 X2 X3] (Matlab syntax)','and then enter:',' F=X*C','where C has also already been entered for you, and is a column','vector containing the coefficients of of the function F(X1,X2,X3)','ie: C=[14;16;15] has been entered for you.','(end of problem 172)')
return %end of problem 172, return to main environment
elseif (findstr(r,'hint')>=1)
hint
else
eval(r,'errormessage')
noprint=0; %resets error suppression
err=0;
end
end %inner while loop end
elseif (findstr(r,'hint')>=1)
hint %call hint file
else
eval(r,'errormessage')
noprint=0; %resets error suppression
err=0;
end %if-else loop end
end %while loop end