请问含积分非线性规划为何出错?。
Show older comments
目标函数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:请问非线性规划可以含积分吗?
Accepted Answer
More Answers (0)
Categories
Find more on 优化 in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!