fmincon with a scheduling problem
1 次查看(过去 30 天)
显示 更早的评论
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
(the link where I found this example is http://www.google.it/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&ved=0CD0QFjAA&url=http%3A%2F%2Ffacs.maru.net%2Fsource_documents%2Fbioprocess_design_opt%2Fweek2_ch1.ppt&ei=E7B6UYXzMrCU7QbX1oH4DQ&usg=AFQjCNGjacf_tLg1QqnlNMF8z_fi58vnAQ&sig2=De3X5lbmEsfXU051c3qfSw&bvm=bv.45645796,d.ZGU)
Thanks in advice.
3 个评论
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 个)
Matt J
2013-4-26
The error means that MATLAB could not find 'objec_func_E15'. It is apparently not on the path.
0 个评论
另请参阅
类别
在 Help Center 和 File 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!