Simscape resistance randomization does not occur when running simulation with fast-restart

6 views (last 30 days)
Hello,
I am trying to simulate a model of a resistor with some random tolerance as shown below. Everything works well when I hit the run the simulation with fast-restart off. Everytime I do so, I get a new random value displayed showing the resistor randomization working as I expect and I gaussian distribution of resistor values for different runs. However, when I run the model with fast restart option on, the model runs but without randomization. The last random value sticks for all simulations. Is there a way to force such randomization to take place even with fast restart?

Accepted Answer

MULI
MULI on 19 Feb 2024
The Fast Restart feature in Simulink is designed to speed up the simulation especially when minor changes are made between runs that do not need to recompile the model every time.
In fast restart mode, the model is initialized only once, and then subsequent simulation runs reuse the model state from the end of the previous simulation run. Due to this, the same random value for the resistor appears in each run when fast restart is turned on.
You can refer this link for more information related to Fast restart in Simulink.
You can try this solution to generate random value even in fast restart mode is on by using “MATLAB Function” block with the following code.
function R = randomResistor()
% Seed the random number generator based on the current time
rng('shuffle');
% Define the mean (nominal) value of the resistor
meanValue = 1000; % 1000 ohms nominal value
% Calculate 1% of the mean value for the tolerance
tolerance = meanValue * 0.01; % 1% tolerance
% Generate a random resistor value with Gaussian distribution
tempValue = meanValue + tolerance * randn();
% Clip the value to ensure it's within the 1% tolerance range
R = min(max(tempValue, meanValue - tolerance), meanValue + tolerance);
end

More Answers (0)

Categories

Find more on Electrical Systems in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!