我正试图解决以下问题,但有一些困难。有人能给我指点吗?
格朗德维尔有很多游客。格兰德维尔的街道从东到西,从.,S. 2街,S. 1街,百老汇街,N. 1街,N.第2街,.大街从北到南,从.,E. 2大道,E. 1大道,百老汇大街,W. 1大道,W. 2大道,.这些街道形成一个方形的街区网格。对于下面的每一个问题,游客从百老汇街和百老汇大街的交汇处开始,在四个主要方向上各移动一个街区的概率相等。
( Q1)游客从百老汇和百老汇出发10步后,至少有3个街区(就像乌鸦飞的那样)的概率有多大?
( Q2)游客从百老汇和百老汇跑完60步后,至少有10个街区(就像乌鸦飞的那样)的概率有多大?
Q3)游客从百老汇和百老汇出发,在10步之内至少有5个街区(就像乌鸦飞的那样)的概率有多大?
( Q4)游客从百老汇和百老汇走过至少10个街区(就像乌鸦飞的那样)在60步以内的概率是多少?
( Q5)游客在东一大道以东10步到达西一大道以西的概率是多少?
( Q6)游客在东一大道以东而在西一大道以西30步到达的概率是多少?
( Q7)在游客第一次从百老汇和百老汇出发,至少有10个街区(就像乌鸦一样)之前,游客的平均移动次数是多少?
( Q8)在游客第一次从百老汇和百老汇出发,至少有60个街区(就像乌鸦一样)之前,游客的平均出行次数是多少?
我正在运行这个matlab代码。但我不知道如何才能找到第一个问题的可能性呢?
function random_walk_2d_simulation ( step_num, walk_num )
%*****************************************************************************80
%
%% RANDOM_WALK_2D_SIMULATION simulates a random walk in 2D.
%
% Discussion:
%
% The expectation should be that, the average distance squared D^2
% is equal to the time, or number of steps N.
%
% Or, equivalently
%
% average ( D ) = sqrt ( N )
%
% The program makes a plot of both the average and the maximum values
% of D^2 versus time. The maximum value grows much more quickly,
% and that curve is much more jagged.
%
% Licensing:
%
% This code is distributed under the GNU LGPL license.
%
% Modified:
%
% 03 November 2009
%
% Author:
%
% John Burkardt
%
% Parameters:
%
% Input, integer STEP_NUM, the number of steps to take in one test.
%
% Input, integer WALK_NUM, the number of walks to take.
%
%
% Set up arrays for plotting.
%
time = 0 : step_num;
d2_ave = zeros(step_num+1,1);
d2_max = zeros(step_num+1,1);
%
% Take the walk WALK_NUM times.
%
for walk = 1 : walk_num
x = zeros(step_num+1,1);
y = zeros(step_num+1,1);
for step = 2 : step_num + 1
%
% We are currently at ( X(STEP-1), Y(STEP-1) ).
% Consider the four possible points to step to.
%
destination = [ x(step-1) + 1.0, y(step-1); ...
x(step-1) - 1.0, y(step-1); ...
x(step-1), y(step-1) + 1.0; ...
x(step-1), y(step-1) - 1.0 ];
%
% Choose destination 1, 2, 3 or 4.
%
k = ceil ( 4.0 * rand );
%
% Move there.
%
x(step) = destination(k,1);
y(step) = destination(k,2);
%
% Update the sum of every particle's distance at step J.
%
d2 = x(step)^2 + y(step)^2;
d2_ave(step) = d2_ave(step) + d2;
d2_max(step) = max ( d2_max(step), d2 );
end
end
%
% Average the squared distance at each step over all walks.
%
d2_ave(:,1) = d2_ave(:,1) / walk_num;
%
% Make a plot.
%
clf
plot ( time, d2_ave, time, d2_max, 'LineWidth', 2 );
xlabel ( 'Time' )
ylabel ( 'Distance squared' )
title_string = sprintf ( '2D Random Walk Ave and Max - %d walks, %d steps', walk_num, step_num );
title ( title_string );
return
end下面是运行以下命令random_walk_2d_simulation的情节(60,10000)

发布于 2015-10-29 19:01:21
这是一个随机游动问题。你可以写一个相当简单的随机漫步模拟,只要游客在离起点60个街区的地方就结束了。在任何给定的时间,你只需要知道游客的x,y坐标。然后每一次步骤,你选择一个方向和增量x或y,然后你需要跟踪距离(0,0)。这大概应该是欧几里得距离,因为这都是乌鸦飞的样子。
https://datascience.stackexchange.com/questions/8649
复制相似问题