Blocks updates persistent or state variables while computing outputs
18 views (last 30 days)
Show older comments
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 Comments
Sargondjani
on 20 Sep 2021
what are the state variables? I mean, the error suggests that you change your state variables in the function optimal_heading
Answers (0)
See Also
Categories
Find more on Event Functions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!