fsolve usage in Simulink fails due to P-code error
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Ver también
Categorías
Más información sobre Manual Performance Optimization en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!