필터 지우기
필터 지우기

simulate a random walk in 1D which can move both in x and -x direction and plot it using normal distribution with standard deviation1 and mean 0

조회 수: 10 (최근 30일)
want tosimulate a random walk in one dimension such that a particle is at the origin (Name this point as A). The particle can move in both the directions (say x and -x). The step to move should be generated as a normal random variable with 0 mean and standard deviation equal to 1. how get steps for normal distribution??
N = 500 ; % number of steps
X = 1; % number of dimensions
% positions, starting at (0,0,...,0)
P = cumsum(full(sparse(1:N, randi(X,1,N), [0 2*randi([0 1],1,N-1)-1], N, X))) ;
% visualisation
figure ;
hold on ;
for k=1:size(P,2),
plot(1:size(P,1),P(:,k),'.-') ;
text(size(P,1),P(end, k), sprintf(' dim %d',k)) ;
end
xlabel('Step') ;
ylabel('Position') ;
hold off ;

채택된 답변

Antonio Aguirre
Antonio Aguirre 2020년 8월 13일
To generate a single random number from a normal distribution you can excute the following code:
% Where r is a random number from a distribution have a mean of zero and standard deviation of 1
r = normrnd(0,1)

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 8월 16일

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by