Solving goal programming problem with MATLAB
12 views (last 30 days)
Show older comments
Please, can someone help me chech what is wrong with my code for the problem below:
Question:
Solve the following goal programming problem given below
objective 1 (yield goal)
208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956 >= 6611
objective 2 (budget goal)
2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5) <= 492
Objective 3 (Chemical goal)
22*x(2)+4*x(3) <= 212
Objective 4 (Seed goal)
x(4) <= 70
Weights = [0.5 0.17 0.13 0.25]
Solution:
fun = @(x)[208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3)];
goal = [6611,492,212,70];
weight = [0.5,0.17,0.13, 0.25];
x0 = [3000,2000,100,35];
x = fgoalattain(fun,x0,goal,weight)
Error Message:
Index exceeds matrix dimensions.
Error in
@(x)[208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3)]
Error in goalcon (line 64)
f = feval(funfcn{3},x,varargin{:});
Error in fgoalattain (line 406)
[ctmp,ceqtmp] = feval(cfun{3},xnew,extravarargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. Optimization cannot continue.
0 Comments
Answers (2)
Torsten
on 15 Feb 2024
Edited: Torsten
on 15 Feb 2024
x0 must be a vector of size 1x5, not 1x4.
Further, your function must return a vector of length 4, not 3.
Further, the first objective must be multiplied by (-1) in order to get <= instead of >=.
fun = @(x)[-208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3);x(4)];
goal = [-6611,492,212,70];
weight = [0.5,0.17,0.13, 0.25];
x0 = [3000,2000,100,35,22];
x = fgoalattain(fun,x0,goal,weight)
0 Comments
John D'Errico
on 15 Feb 2024
Edited: John D'Errico
on 15 Feb 2024
READ THE ERROR MESSAGE! What did it say?
"Failure in initial user-supplied objective function evaluation. Optimization cannot continue."
Surely that was returned for a reason. Here was your code:
fun = @(x) [208*x(1)^0.323168*x(2)^0.172084*x(3)^0.085998*x(4)^0.188794*x(5)^0.229956;2.8*x(1)+22*x(2)+4*x(3)+0.272*x(4)+x(5);22*x(2)+4*x(3)];
x0 = [3000,2000,100,35];
Now, a thing I always strongly suggest when someone uses an optimizer, is to test to see if the objective function even works.
fun(x0)
Now, why might that fail? Your objective is a function of FIVE unkowns. Yet you gave it only 4 starting values.
1 Comment
Ezra
on 15 Feb 2024
Thank you all for your observations, comments and solutions. I would take time to go over them and do all the necessary amendment.
Merci beaucoup
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!