reverse the output order of the constraint function argument of fmincon

1 回表示 (過去 30 日間)
Leo Simon
Leo Simon 2018 年 4 月 2 日
回答済み: Walter Roberson 2018 年 4 月 2 日
I frequently use fmincon to solve for a bunch of equality constraints, but my problems have no inequality constraints. My equality constraints are typically defined as an anonymous function in the workspace that calls fmincon, e.g.,
f = @(x,b) a*x + b
It would be so much more convenient if I could simply pass f as an argument to fmincon, e.g.,
soln = fmincon(obj,x,[],[],[],[],[],[],@(x) f(a,b))
but because fmincon expects equality constraints in the second argument, I have to write a separate nested function with two output variables, and all of the data to that extra function. Is there a workaround for this? I can think of two ways it could be done: easiest would be for matlab to provide a field of the fmincon options struct that reversed the output arguments of the constraint function. Alternatively, is there a way to write an anonymous function with two output arguments? Thanks!

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 2 日
@(x) deal([], f(x, b))

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by