필터 지우기
필터 지우기

How to programmatically stop simulation when output converges

조회 수: 9 (최근 30일)
Yunyu Hu
Yunyu Hu 2020년 2월 22일
답변: Vimal Rathod 2020년 2월 27일
I am running a model to do somthing like Monta Carlo simulation.
The output will get to a stable value after enough time, sometimes it takes longer, sometimes it takes less time.
To save the simulation time (there are several thousands of simulations to do), how can I programmatically set dynamic simulation time or stop simulation when output gets stable?
If there is even a solution for parallel computing, that would be even better.
Thanks and BR
  댓글 수: 2
Walter Roberson
Walter Roberson 2020년 2월 22일
Is this Simulink or pure MATLAB ?
Yunyu Hu
Yunyu Hu 2020년 2월 26일
Hi,
the model is in Simulink.
to run the model with varying parameters I use some thing like this:
k = Simulink.Parameter
k.CoderInfo.StorageClass = 'SimulinkGlobal';
k.Value = -0.9;
mdl = 'sldemo_bounce';
rtp = Simulink.BlockDiagram.buildRapidAcceleratorTarget(mdl);
k_values = [-0.9:0.1:-0.1];
for i = 1:length(k_values)
paramSet(i) =
Simulink.BlockDiagram.modifyTunableParameters(rtp, ...
'k', k_values(i));
end
for i = 1:length(k_values)
simout(i) = sim(mdl,'SimulationMode','rapid',...
'RapidAcceleratorUpToDateCheck','off', ...
'RapidAcceleratorParameterSets',paramSet(i));
end
But as I said, in my model the simulation output will reach a stable value after certain time, and this time is varying. Because the simulation amount is huge, therefore I think if I can dynamically stop the simulation when the value stablizes, thus I can save some time?
Thanks and BR

댓글을 달려면 로그인하십시오.

채택된 답변

Vimal Rathod
Vimal Rathod 2020년 2월 27일
You could use a Stop Simuation Block to stop the simulation by defining a condition which you want to satisfy before stopping the simulation.
You need to construct some logic which gives a boolean input to the stop simulation block.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Monte-Carlo에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by