Adding random noise in different timestep while numerical integration

조회 수: 1 (최근 30일)
Thomas Tanzer
Thomas Tanzer 2021년 1월 16일
답변: Dongyue 2022년 11월 18일
How can I add a "random factor" only in every second integration step?
Because maybe I don't want to add the Random all the time - for example I Want to add it in time steps = 0.004 or maybe 0.008.
dt = 0.002;
end_1 = 2.0;
time = 0:dt:end_1;
Matrix = zeros(10,length(time);
Matrix(:,0.5/dt:0.6/dt) = repmat(...);
Random = randn(10,length(time);
Matrix = Matrix + Random;
what is the best way to add Random in a different tilmestep than dt?
This dt = 0.002 will later serve as an integration step for solving a differential equation where matrix occurs - now, however, I would like to add the random component in, for example, coarser time steps (every 2nd ... or possibly only every 10th step).

답변 (1개)

Dongyue
Dongyue 2022년 11월 18일
Hi Thomas,
You can use mod() function as a flag, to trigger the adding ramdom process.
if mod(time, 0.04)==0
Matrix = Matrix + Random;
end
For detailed information of mod() function, please go through the link below:
Best,
Dongyue

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by