An error message using fmincon

3 ビュー (過去 30 日間)
ektor
ektor 2019 年 5 月 25 日
コメント済み: ektor 2019 年 5 月 26 日
Dear all,
I minimize this function.
g=randn(1000,1);
u=randn(1000,1);
ff = @(x) sum( ( g(2:end)- x(1)- x(2)*(g(1:end-1)-x(1)) - u(2:end)*x(3) ).^2 );
xx = fmincon(ff,[0.1 0.2 0.3],[],[],[],[],[],[],@unitdisk3,options);
where
function [c,ceq] = unitdisk3(x)
c = [ x(2)-0.999; -x(2)-0.999 ;- x(3) +0.001 ];
ceq = [];
end
but I get this error message
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
Error in unitdisk3 (line 2)
c = [ x(2)-0.999; -x(2)-0.999 ;- x(3) +0.001 ];
Error in fmincon (line 633)
[ctmp,ceqtmp] = feval(confcn{3},X,varargin{:});
Caused by:
Failure in initial nonlinear constraint function evaluation. FMINCON cannot
continue.
Any ideas why?

採用された回答

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019 年 5 月 26 日
Hi Ektor,
You have done a good work except for two small flaws, but crucial ones. Here are the corrected scripts:
function [c,ceq] = unitdisk3(x)
c = [ x(1)-0.999, -x(2)-0.999 , - x(3) +0.001 ];
ceq = [];
end
g=randn(1000,1);
u=randn(1000,1);
options = optimoptions('fmincon','Display','off', 'Algorithm', 'active-set');
ff = @(x) sum((g(2:end)- x(1)- x(2)*(g(1:end-1)-x(1)) - u(2:end)*x(3)).^2);
xx = fmincon(ff,[0.1 0.2 0.3],[],[],[],[],[],[],@unitdisk3,options);
Good luck.
  1 件のコメント
ektor
ektor 2019 年 5 月 26 日
Great!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by