fsolve usage in Simulink fails due to P-code error
조회 수: 4 (최근 30일)
이전 댓글 표시
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!