请问含积分非线性规划为何出错?。

目标函数m文件:
function f = objfun(x)
f = exp(x(1))*(4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1)+quad((x(1)+F).^2.5,-1,1)
约束条件函数m文件:
function [c, ceq] = confun(x)
% Nonlinear inequality constraints
c = [1.5 + x(1)*x(2) - x(1) - x(2);
-x(1)*x(2) - 10];
% Nonlinear equality constraints
ceq = [];
Command Window:
>> F=@(u)(sqrt(u).*normpdf(u,0,1))
F =
@(u)(sqrt(u).*normpdf(u,0,1))
>> x0 = [-1,1]; % Make a starting guess at the solution
options = optimset('Algorithm','active-set');
[x,fval,exitflag,output,lambda,grad,hession]=fmincon(@objfun,x0,[],[],[],[],[],[],@confun,options);
结果:
Undefined function or variable 'F'.
Error in objfun (line 2)
f = exp(x(1))*(4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1)+quad((x(1)+F).^2.5,-1,1)
Error in fmincon (line 601)
initVals.f = feval(funfcn{3},X,varargin{:});
Caused by:
Failure in initial user-supplied objective function evaluation. FMINCON cannot continue.
已经在Command Window中定义了F,为何还是出错,向大家求助,谢谢!
PS:请问非线性规划可以含积分吗?

 採用された回答

volabah
volabah 2022 年 11 月 24 日

0 投票

F 的定义应该放在 objfun.m 里,或者以参数形式传进去,否则,F 相对于子函数 objfun 是未定义的
function f = objfun(x)
F=@(u)(sqrt(u).*normpdf(u,0,1));
f = exp(x(1))*(4*x(1)^2 + 2*x(2)^2 + 4*x(1)*x(2) + 2*x(2) + 1)+quad(@(u)(x(1)+F(u)).^2.5,-1,1);

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange优化 についてさらに検索

タグ

質問済み:

2022 年 11 月 24 日

回答済み:

2022 年 11 月 24 日

Community Treasure Hunt

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

Start Hunting!