fmincon unidentified variable in objective function

조회 수: 5 (최근 30일)
bus14
bus14 2019년 5월 8일
편집: Matt J 2019년 5월 8일
Hi, I am running a fmincon code to optimize a function. However in my objective function an error occurs that says I have a undefined variable 'x'.
This is however what I want to optimize. Does anyone see what I am doing wrong?
%= [x1 x2 x3 w1 y1 w2 y2 w3 w4]=[v1 v2 v3 v4 v5 v6 v7 v8 v9]
%objective = min 150x1+230x2+260x3+238y1-170w1+210y2-150w2-36w3-10w4
% all constraints are inequality and should all be smaller then
% multiply greater than by -1
FUN= 150*x(1)+230*x(2)+260*x(3)+238*x(5)-170*x(4)+210*x(7)-150*x(6)-36*x(8)-10*x(9);
%FUN= @v 150*v(1)+230*v(2)+260*v(3)+238*v(5)-170*v(4)+210*v(7)-150*v(6)-36*v(8)-10*v(9);
x0=[50,50,50,50,50,50,50,50,50];
A=[ 1 1 1 0 0 0 0 0 0; -2.5 0 0 1 -1 0 0 0 0;0 -3 0 0 0 1 -1 0 0;0 0 -20 0 0 0 0 1 1;0 0 0 0 0 0 0 1 0];
b=[500;-200;-240;0;6000];
lb=[zeros(1,9)];
ub=[];
sol = fmincon(FUN,x0,A,b,[],[],lb,ub)
Thanks

채택된 답변

Matt J
Matt J 2019년 5월 8일
편집: Matt J 2019년 5월 8일
This should fix it,
FUN= @(x)150*x(1)+230*x(2)+260*x(3)+238*x(5)-170*x(4)+210*x(7)-150*x(6)-36*x(8)-10*x(9);
however, you should really consider using linprog instead. fmincon is overkill for such a simple linear problem.
  댓글 수: 4
John D'Errico
John D'Errico 2019년 5월 8일
Yep. bus14 asked the same question again. I showed that the vector
120
80
300
100
k
0
k
6000
0
yields an arbitrarily large negative result for any positive k, is always feasible, and clearly satisfies the bound constraints.
Matt J
Matt J 2019년 5월 8일
편집: Matt J 2019년 5월 8일
I think there's a discrepancy between the two threads. I get a bounded solution (the same one) and exitflag=1 with both solvers.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by