fmincon with a scheduling problem
Afficher commentaires plus anciens
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 commentaires
I copied the code but I get errors: some one could tell me why?
Not until you post the errors so that we can see them (copy/pasted exactly).
Incidentally, beware the hazards of global variables! There are better alternatives, e.g.,
[x, fval] = fmincon(@(x) objec_func_E15 (x,M,S) ,x0,...)
function f=objec_fun_E15(x,M,S)
f=-(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));
Matt J
le 26 Avr 2013
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.
Réponses (2)
Marco Rebecchi
le 26 Avr 2013
Modifié(e) : Matt J
le 26 Avr 2013
0 votes
Matt J
le 26 Avr 2013
0 votes
The error means that MATLAB could not find 'objec_func_E15'. It is apparently not on the path.
Catégories
En savoir plus sur Solver Outputs and Iterative Display dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!