fmincon with a scheduling problem

1 次查看(过去 30 天)
Marco Rebecchi
Marco Rebecchi 2013-4-26
Hello everyone! I found an example of scheduling with fmincon on the web. It is a scheduling problem about the production of two plants. I copied the code but I get errors: some one could tell me why?
The code is the following
global M;
global S;
M(1,1) = 130; M(1,2) = 150;
M(2,1) = 160; M(2,2) = 180;
S(1,1) = 30; S(1,2) = 40;
S(2,1) = 35; S(2,2) = 45;
%STOCK LIM
L1 = 70000;
x0 = [200; 100; 100; 200];
A = [0 M(1,2) 0 M(2,2)];
b = L1;
Aeq = [1 1 0 0; 0 0 1 1];
beq = [300; 300],
lb = [0; 0; 0; 0];
ub = [inf; 300; inf; 300];
[x, fval] = fmincon(@objec_func_E15,x0,A,b,Aeq,beq,lb,ub)
with objective function
function f=objec_fun_E15(x)
global M;
global S;
s=x(1,1)*M(1,1)*S(1,1) + x(2,1)*M(1,2)*S(1,2) + x(3,1)*M(2,1)*S(2,1) + x(4,1)*M(2,2)*S(2,2);
f = -s
Thanks in advice.
  3 个评论
Matt J
Matt J 2013-4-26
编辑:Matt J 2013-4-26
Incidentally also, since your objective function and constraints are all linear, you should consider using LINPROG instead of FMINCON.
Matt J
Matt J 2013-4-26
Marco Rebecchi Commented:
You're right, the errors were
??? Error using ==> feval Undefined function or method 'objec_func_E15' for input arguments of type 'double'.
Error in ==> fmincon at 574 initVals.f = feval(funfcn{3},X,varargin{:});
Error in ==> Knapsack26042013 at 31 [x, fval] = fmincon(@objec_func_E15,x0,A,b,Aeq,beq,lb,ub)
Caused by: Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
Now I'll try with your solution.

请先登录,再进行评论。

回答(2 个)

Marco Rebecchi
Marco Rebecchi 2013-4-26
编辑:Matt J 2013-4-26
Relocated to Comment by Matt J

Matt J
Matt J 2013-4-26
The error means that MATLAB could not find 'objec_func_E15'. It is apparently not on the path.

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by