フィルターのクリア

MATLAB Coder Error - optimset Unrecognized parameter name: 'GradObj'

9 ビュー (過去 30 日間)
Vadim Bertrand
Vadim Bertrand 2021 年 6 月 9 日
編集済み: Steve Grikschat 2021 年 6 月 10 日
Hi,
I'm trying to generate C code of a function using MATLAB Coder but I am getting the following error when generating MEX:
Unrecognized parameter name: 'GradObj'
Full instruction is:
optionsNLP = optimset('GradObj', 'off', 'GradConstr', 'off', ...
'DerivativeCheck', 'off', 'Display', 'iter', 'TolX', 1e-9, ...
'TolFun', 1e-9, 'TolCon', 1e-9, 'MaxFunEval', 300, 'DiffMinChange', 1e-5);
It is working when I run the MATLAB script directly.
I am thinking that maybe it can not be generated because a Toolbox is required to use the GradObj parameter?
Does anyone knows a workaround if any?
Thanks.
Vadim

採用された回答

Steve Grikschat
Steve Grikschat 2021 年 6 月 9 日
編集済み: Steve Grikschat 2021 年 6 月 10 日
Hi Vadim,
For generating C code for fmincon (or lsqnonlin, etc.) via MATLAB Coder, we require that you use the optimoptions function to set options. See the requirements in this documentation page.
Also, an important note is that only the SQP algorithm of fmincon is supported for C code generation.
The equivalent code for your example is as follows
optionsNLP = optimoptions('fmincon','Algorithm','sqp','SpecifyObjectiveGradient', false, ...
'CheckGradients', false, 'Display', 'iter', 'StepTolerance', 1e-9, 'FunctionTolerance', 1e-9, ...
'ConstraintTolerance', 1e-9, 'MaxFunctionEvaluations', 300, 'DiffMinChange', 1e-5);
  3 件のコメント
Vadim Bertrand
Vadim Bertrand 2021 年 6 月 10 日
I just noticed a small typo in the code sample you provided:
optionsNLP = optimoptions('fmiuncon',...)
Should be:
optionsNLP = optimoptions('fmincon'
Steve Grikschat
Steve Grikschat 2021 年 6 月 10 日
Good catch! Thanks for pointing that out.
I guess I should have tried the new "Run" button on my answer. :)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by