Error using the fmincon function

8 ビュー (過去 30 日間)
Giacomo
Giacomo 2025 年 5 月 12 日
コメント済み: Giacomo 2025 年 5 月 15 日
This is my code:
nonlcon = @(x) deal(g_fun_vec(x), []);
options = optimoptions('fmincon','Algorithm','sqp','Display','iter');
[x_sol,~,exitflag, output] = fmincon(@(x) 0, x0, [], [], [], [], lb, ub, nonlcon, options);
And I get this error message:
The strange things is that, as you can see on the screenshoot of the Command Window, the constraint fuction is defined correctly at x0
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 5 月 12 日
Although nonlcon is not specifically documented as having to return real values,
Nonlinear constraints, specified as a function handle or function name. nonlcon is a function that accepts a vector or array x and returns two arrays, c(x) and ceq(x).
  • c(x) is the array of nonlinear inequality constraints at x. fmincon attempts to satisfyc(x) <= 0 for all entries of c.
  • ceq(x) is the array of nonlinear equality constraints at x. fmincon attempts to satisfyceq(x) = 0 for all entries of ceq.
If c(x) were permitted to be complex, then c(x) <= 0 is not well defined. If c(x) were permitted to be complex, then is the implied definition real(c(x))<=0 or would it be real(c(x))<=0 & imag(c(x))<=0 -- leaving open the possibility that c(x) were (for example) -1-1i as satisfying constraints ?

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

採用された回答

Matt J
Matt J 2025 年 5 月 12 日
編集済み: Matt J 2025 年 5 月 12 日
No, the constraint and objective functions have to return real values to be considered "defined". Possibly you have log() or sqrt() operations in your constraints that produce complex values when their arguments go negative.
  1 件のコメント
Giacomo
Giacomo 2025 年 5 月 15 日
Yes, thanks I didn't put the expression in abs()

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by