Borrar filtros
Borrar filtros

fsolve usage in Simulink fails due to P-code error

4 visualizaciones (últimos 30 días)
Sully
Sully el 8 de Abr. de 2022
Editada: Christian el 9 de En. de 2024
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.

Respuestas (1)

Christian
Christian el 9 de En. de 2024
Editada: Christian el 9 de En. de 2024
Initialize lam_the=0; in the first line of the function.
Matlab just fails to provide a proper Error.

Categorías

Más información sobre Manual Performance Optimization en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by