Why does the same function generate different results when coder.extrinsic is ON or OFF?

2 ビュー (過去 30 日間)
Yves Stauffer
Yves Stauffer 2014 年 12 月 15 日
編集済み: Angelo Yeo 2022 年 8 月 26 日
In the attached file, there is a simulink block that:
  • Calls a TestFunction directly
  • Calls the TestFunction through a wrapper
at the end the result of the two function calls are compared.
If the following line:
coder.extrinsic('wrapper');
is commented, the two function calls give the same results. However, if that line is not commented very small differences arise.
Where do these difference come from? And more importantly, how can I get exactly the same result by having following line not commented?
coder.extrinsic('wrapper');
I have performed the test under Matlab 2013a 32bit and 2014a 32bit.

回答 (1 件)

Angelo Yeo
Angelo Yeo 2022 年 8 月 26 日
編集済み: Angelo Yeo 2022 年 8 月 26 日
This is because math kernel libraries for code-gen fmincon and MATLAB engine's are different. This is explained in the doc "fmincon".
https://www.mathworks.com/help/optim/ug/fmincon.html#refsect-extended-capabilities:~:text=Code%20generation%20targets%20do%20not%20use%20the%20same%20math%20kernel%20libraries%20as%20MATLAB%20solvers.%20Therefore%2C%20code%20generation%20solutions%20can%20vary%20from%20solver%20solutions%2C%20especially%20for%20poorly%20conditioned%20problems.

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by