필터 지우기
필터 지우기

using a seed for normal random number

조회 수: 17 (최근 30일)
dav
dav 2013년 3월 21일
Hi,
I am using the following code in a simulation. I need to use a seed to generate the same random numbers. can you please help me with it?
thanks
a0 = 0.1; a1 = 0.4;
epsi=zeros(3000,1);
simsig=zeros(3000,1);
for i = 1:3000
if (i==1)
simsig(i) = a0/(1-a1) ;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
else
simsig(i) = a0+ a1*(epsi(i-1))^2;
s=(simsig(i))^0.5;
epsi(i) = normrnd(0,1) * s;
end
end

채택된 답변

Peter Perkins
Peter Perkins 2013년 3월 21일
dav, as long as you're using a fairly recent version of MATLAB, the rng function is what you want to use. For reproduceability, you can probably just use something like
rng(seed)
but this page
describes a whole set of scenarios.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by