After I successfully run the fmincon Optimization tool on my objective function, I generate code. When I try to run the computer generated code it does not run. Gives error message.

1 visualizzazione (ultimi 30 giorni)
My objective Function is V=Pvariance(A,B,C,W)
After I successfully run the fmincon Optimization tool on my objective function, I generate code. When I try to run the computer generated code it does not run. Gives error message.
The computer generated code is:
function [x,fval,exitflag,output,lambda,grad,hessian] = minPvariance3(x0,Aeq,beq,lb)
%%This is an auto generated MATLAB file from Optimization Tool.
%%Start with the default options
options = optimoptions('fmincon');
%%Modify options setting
options = optimoptions(options,'Display', 'off');
options = optimoptions(options,'Algorithm', 'active-set');
[x,fval,exitflag,output,lambda,grad,hessian] = ...
fmincon(@(W)Pvariance(A,B,C,W),x0,[],[],Aeq,beq,lb,[],[],options);
Notice that the variables A,B,C are missing from the first line.
When I run this code I get the following error message even though the Variables A,B,C are in the workspace.
Undefined function or variable 'A'.
Error in minPvariance3/@(W)Pvariance(A,B,C,W)
Error in fmincon (line 635)
initVals.f = feval(funfcn{3},X,varargin{:});
Error in minPvariance3 (line 9)
[x,fval,exitflag,output,lambda,grad,hessian] = ...
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot
continue.
Please help me solve this problem. Thanks
  2 Commenti
Matt J
Matt J il 12 Mag 2013
It sounds like you already know what the problem is. You said yourself that A,B,C are missing. Isn't the obvious solution to supply them?
Andrew
Andrew il 12 Mag 2013
Yes, Matt. I did try to insert them in the "run" command. I get the error message: too many input arguments.
I have run these generated code in my previous teachers computer. They run fine. The reason I was able to spot the missing A,B,C is that in his generated codes the A,B,Cs were there. Here is a code that runs:
function [x,fval,exitflag,output,lambda,grad,hessian] = minPvariance(A,B,C,x0,Aeq,beq,lb) %% This is an auto generated MATLAB file from Optimization Tool.
%% Start with the default options options = optimset; %% Modify options setting options = optimset(options,'Display', 'off'); options = optimset(options,'Algorithm', 'active-set'); [x,fval,exitflag,output,lambda,grad,hessian] = ... fmincon(@(W)Pvariance(A,B,C,W),x0,[],[],Aeq,beq,lb,[],[],options);
I think I need the right settings that generate the right code. Thanks.
Andy

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by