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.
9 次查看(过去 30 天)
显示 更早的评论
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 个评论
Matt J
2013-5-12
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?
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Problem-Based Optimization Setup 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!