Number of values stored are more than the ratio of stop Time/Step size ?

1 view (last 30 days)
I am using presistance variables as cells to store values in the Matlab Interpreted block of simulink, My Step Size is 0.001 and my Stop Time 0.005 and the number of values stored is 16. (Even though I reduce the Stop Time to 0.001 the number of values stored is 4.) It seems Simulation file is called Matlab Interpreted block 16 times istead of 5 times. How can I fix this issue ?
  5 Comments
kintali narendra
kintali narendra on 24 Sep 2023
Hi Atsushi, @Atsushi Ueno
Thanks for the response. This is the logic I am using to update the persistant variables.
function [out] = Voltage_calc(In)
persistent VAmin0 VFmin0
Tdes = In(1);
Wm = In(2);
if Wm > 0
RA = 2.581; RF = 281.2; K = 1.8;
a = (RA*Tdes)/K;
b = K*Wm;
phi = max([sqrt(a/b) 0.1])
VAmin0(end+1,1) = a*(1/phi) + (b*phi)
a_amp = 2; b_rise = 0.55; c_offset = 0;
d = max([(2*a_amp./(phi+a_amp))-1 0.7405]);
iFmin = (-1/b_rise)*log( d )-c_offset;
VFmin0(end+1,1) = RF*iFmin
VAmin = VAmin0(end,1);
VFmin = VFmin0(end,1);
else
VAmin0(end+1,1) = 240;
VFmin0(end+1,1) = 300;
VAmin = VAmin0(end,1);
VFmin = VFmin0(end,1);
end
out = [VAmin VFmin size(VAmin0,1) size(VFmin0,1) size(VAmin0,2) size(VFmin0,2)];
Atsushi Ueno
Atsushi Ueno on 24 Sep 2023
Thank you. Now I can confirm that the size of persistent variables increased by 1 per one execution of the function.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 24 Sep 2023
Variable-step solvers are sort of like walking in a mountain in the dark, when equipped with a narrow-beam flashlight that you can use to send out quick pulses of light. Any one pulse of light might show that a particular spot in the distance has a particular height, but it doesn't directly tell you anything about what is in-between where you are and that spot, and any one pulse of light does not give you any direct information about what the best direction to travel is. The variable solver is instead like saying, "Taking a guess that you are currently safe to take a step that is so-many metres long, shine your light at several different places according to this carefully different pattern, and use the information from those locations to make a prediction about what the local terrain is like. To confirm that your prediction is right, shine your light at a different carefully-calculated location and make sure that the ground is within a certain range of heights: if it is, then trust your prediction of the local terrain and make the step. If the confirmation check shows a height that is not within a certain range, then that means that you misjudged the terrain, and start again from where you are but with a smaller step size -- but if your prediction was successful then increase your step size by a little."
Which is to say, that variable-step solvers evaluate the function at a number of places they do not intend to step to, in order to evaluate information about the local function space in order to be able to make good predictions of the best way to go. You typically have no reason to want to record the results at those locations that were probed: you typically only want to record the results at the locations that you actually step to. But with your persistent variable, you are recording information about every invocation, not just every successful step.
When you switch to discrete time, the solver switches to fixed-step rather than variable-step. You might also need to change some of the blocks in your model -- for example if you have integrator blocks you might need to switch to discrete integrator blocks.

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!