フィルターのクリア

Average trajectory of multiple 2D random walk trajectories

4 ビュー (過去 30 日間)
Kelly McGuire
Kelly McGuire 2019 年 1 月 15 日
編集済み: Kelly McGuire 2019 年 1 月 15 日
How would I plot the average trajectory of multiple 2D random walk traces constrained between two points? Here is the code I am using:
clc
clear all
%Ask for number of rivers
NumberOfSimulations = input('How many rivers? \n');
%Ask for number of steps
n = input('How many steps? \n'); % number of steps, nt increasing and n(t-1) decreasing
%StartPoint
x0=0;
%End point after n steps
xtarg=40;
Saved=NaN*zeros(n+1,NumberOfSimulations+2); %Initializes Array
Saved(1,:)=x0; %Fills first row with x0 value
Saved(n+2,:)=xtarg; %Fills last row with xtarg value
for q = 1:NumberOfSimulations
unifs = rand(n+1,1);
x = x0;
for i = 0:(n-1)
t = (1-(xtarg-x)/(n-i))/2;
if unifs(i+1,1) <= t
x = x-1;
else
x = x+1;
end
Saved(i+2,q) = x;
end
end
figure(1);
hold on;
plot(Saved);
plot(mean(Saved,2),'k','Linewidth',2.5);

回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by