フィルターのクリア

Using fsolve in MATLAB FUNCTION BLOCK in Simulink

31 ビュー (過去 30 日間)
gdz
gdz 2023 年 2 月 1 日
回答済み: Kartik 2023 年 4 月 17 日
Hi,
I am using a S-function builder to read the data from my arduino. The buf0 gives me the reading of the sensor. Then, I would like to send the buf0 as u to the MATLAB FUNCTION BLOCK, and the output is y. However, the output of y gives me 0 all the time, which is not changing with the input u.
function y = fcn(u)
F=@(x)[10*exp(-3*10^(-4)*x)+23*exp(-6*10^(-6)*x)-u];
y = fsolve(F,0,optimoptions('fsolve','Algorithm','levenberg-marquardt'));
I have tried to use MATLAB FUNCTION BLOCK with y = u and it works. So, i believe the problem is with the fsolve function.
Therefore, I would like to ask how to use fsolve in MATLAB FUNCTION BLOCK in Simulink.
Thank you.
  1 件のコメント
gdz
gdz 2023 年 2 月 1 日
編集済み: gdz 2023 年 2 月 1 日
I have verified the MATLAB Function block once again. I discovered that the function works under "Simulation" tab, and it will not work under "Hardware" tab.
Therefore, are there any way allow my function to work under "Hardware" tab?
Thank you.

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

採用された回答

Kartik
Kartik 2023 年 4 月 17 日
Hi,
I understand that you have been trying to use the “fsolve” function with specific arguments (solving algorithm) in the Hardware Tab.
To make sure that your function works under the "Hardware" tab, you need to check if the “fsolve” function is supported for code generation. You can do this by running the following command in the MATLAB Command Window:
cfg = coder.config('lib');
cfg.TargetLang = 'C';
checkCodegenCompatibility(F, cfg);
This command generates C code for the 'F' function using the default code generation configuration ('lib'), which generates a static library. If the “fsolve” function is supported for code generation, the command should run without errors.
If the “fsolve” function is not supported for code generation, the command will return an error message indicating which part of the function is not supported.
If the “fsolve” function is not supported for code generation, you can try using a different solver that is supported, such as “fsolve” with the “trust-region-dogleg” algorithm or “fmincon”.
For more information on using the fsolve function in Simulink, see the following documentation:

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by