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 (최근 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
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?
Andrew
Andrew 2013년 5월 12일
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

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Problem-Based Optimization Setup에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by