Adding random noise in different timestep while numerical integration
2 次查看(过去 30 天)
显示 更早的评论
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).
0 个评论
回答(1 个)
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
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!