1
votes

I want to set a variable step size for every solver step by using the command in the S-function like:

dT= ...   % calculate the dT from the inputs of Block and the parameters of S-function
set_param(gcs,'...',num2str(dT));

However, the Matlab does not provide us with a assignable parameter like 'Step' for specifing the solver step size by using the command "set_param()" above. The callable and assignalbe parameters for the solver step size are only 'MaxStep' and 'MinStep'. Therefore, the following two commands are acceptable and executable in Simulink:

set_param(gcs,'MaxStep',num2str(dT1));
set_param(gcs,'MinStep',num2str(dT2));

Thus, I was trying to assign a same value to dT1 and dT2 in order to get the a certain step size, but there was immediately a error report indicating that the max. step and min. step cannot be the same.

So my question is how to specify a step size to the solver in the script of S-function?

1
Can't you just use a fixed-step solver?Rody Oldenhuis
Because the every step size is different. Fixed-step solver allows a uniform step size for every step and it can be defined only at the initialization.user3518207

1 Answers

1
votes

The solver settings (used by variable step and fixed-step blocks) are set on initialization and can't be changed using the simulation. And I assume the fixed-step solver suggestion in the comments won't work for you as you seem to indicate that you want to change the step size during the simulation.

Generically there is no real mechanism for you to have that sort of control over defining (on a step by step basis) the step size that Simulink takes during the simulation. Nominally that's what the Simulink solver does for you automatically based on the settings during initialization.

You can do it on a block by block basis if all the blocks are S-functions and have a variable step size. And you could do it by running the simulation over a single time step, saving the SimState, determining the next sample time, running for one time step, saving the SimState, etc., but that would be very inefficient.