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

조회 수: 5 (최근 30일)
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?

채택된 답변

MULI
MULI 2024년 2월 19일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Variable Initialization에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by