フィルターのクリア

fsolve usage in Simulink fails due to P-code error

9 ビュー (過去 30 日間)
Sully
Sully 2022 年 4 月 8 日
編集済み: Christian 2024 年 1 月 9 日
Hi,
I would to solve an expression numerically using fsolve in Simulink however I get a P-code function error which I cannot understand.
I am trying to solve the following function in a matlab function block in simulink which works when used in a Matlab script:
function [lam_the] = slip_mag(theta)
% Magic formula
% Unpack
B0 = theta(1,1);
C0 = theta(1,2);
D0 = theta(1,3);
E0 = theta(1,4);
mu0 = theta(1,5);
% Solve
F = @(sig) (D0 * sin(C0 * atan(B0 * sig - E0 * (B0 * sig - atan(B0 * sig)))) - mu0);
opt = optimoptions('fsolve','Algorithm',"levenberg-marquardt");
lam_the = fsolve(F,0.1,opt);
end
Which results in the following error:
Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.
Component: MATLAB Function | Category: Coder error
Index expression out of bounds. Attempted to access element 1. The valid range is 1-0.
More information
P-code function 'driver.p' produced an error.
Component: MATLAB Function | Category: Coder error
Function call failed.
P-code function 'fsolve.p' produced an error.
Component: MATLAB Function | Category: Coder error
Function call failed.
Function 'Particle Filter1' (#24.3081.3098), line 95, column 15:
"fsolve(F,0.1,opt)"
Launch diagnostic report.
Component: MATLAB Function | Category: Coder error
How can I correctly use fsolve in Simulink?
Thank you in advance.

回答 (1 件)

Christian
Christian 2024 年 1 月 9 日
編集済み: Christian 2024 年 1 月 9 日
Initialize lam_the=0; in the first line of the function.
Matlab just fails to provide a proper Error.

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by