Blocks updates persistent or state variables while computing outputs

조회 수: 25 (최근 30일)
Matteo Paiano
Matteo Paiano 2021년 9월 20일
댓글: VIGNESH BALAJI 2024년 1월 24일
In Simulink I had a MATLAB function working properly. I change it a little bit, but now I get the error:
"'DynProg/referenceS/Willners' or the model referenced by it contains blocks that updates persistent or state variables while computing outputs and is not supported in an algebraic loop. The parent subsystem 'DynProg/referenceS' is in an algebraic loop with the following blocks"
function [u_opt,r_des] = optimal_heading(current_X_ASV,X_AUV_list,P_AUV_list,u_max,r_max,Tc_usbl,decisions)
X = current_X_ASV'; Cost = 0; action = [-1 -1]; LA = -1;
coder.varsize('expansion',[10000 7], [1 0])
expansion = [X,Cost,action,LA];
psi_set = (2*r_max*Tc_usbl).*rand(1,decisions) - r_max*Tc_usbl;
u_set = u_max.*rand(1,decisions);
delta_opt = action(1); u_opt = action(2);
r_des = delta_opt/Tc_usbl;
The code is much longer than this, but I tried commenting and uncommenting some lines and I came to the conclusion that the use of rand is somehow responsible for the error. However, if I create a simple function like
function fcn(r_max, Tc_usbl, decisions)
psi_set = (2*r_max*Tc_usbl).*rand(1,decisions) - r_max*Tc_usbl;
for k = 1:numel(psi_set)
delta = psi_set(k)
end
It works fine! The previous version of the function used a simple linspace, and if I still use it instead of rand, the code compile correctly.
Do you have any suggestion! Thanks, really!
  댓글 수: 2
Sargondjani
Sargondjani 2021년 9월 20일
what are the state variables? I mean, the error suggests that you change your state variables in the function optimal_heading
VIGNESH BALAJI
VIGNESH BALAJI 2024년 1월 24일
Did you get a solution for this ? I am also facing similar error

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Event Functions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by