필터 지우기
필터 지우기

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 CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by