摘要
This file was copied from en.wikipedia by Toobaz, what follows is its original description:
Code
Made with the following Python script (needs Matplotlib):
from pylab import *
from random import choice
numwalk = 8
length = 100
data = zeros((numwalk, length), int)
for n in range(numwalk):
for x in range(1, length):
step = choice([-1, 1])
data[n,x] = data[n,x-1] + step
plot(range(length), data[n,:])
xlabel('t')
axis ((0,100, -20, 20))
savefig('Random_Walk_example.svg')
show()
|
已授权您依据自由软件基金会发行的无固定段落及封面封底文字(Invariant Sections, Front-Cover Texts, and Back-Cover Texts)的GNU自由文件许可协议1.2版或任意后续版本的条款,复制、传播和/或修改本文件。该协议的副本请见“GNU Free Documentation License”。http://www.gnu.org/copyleft/fdl.htmlGFDLGNU Free Documentation Licensetruetrue
|
原始上传日志
原始描述頁面位於
這裡。下列使用者名稱均來自en.wikipedia。
- 2008-10-14 18:20 Morn 720×540× (30897 bytes) {{Information |Description= |Source=I created this work entirely by myself. |Date=2008-10-14 |Author=~~~ |other_versions= }} Made with the following Python script: <code> from pylab import * from random import choice numwalk = 8 length = 100 data = z
The following is the similar code in MATLAB and Octave
function RandomWalk ()
hold off;
x = 1:100;
color = ['y' 'g' 'b' 'k' 'r', 'm' 'c'];
y(1)= 0;
for m = 1:7
for n = 2:100
y(n) = y(n-1) + 2*floor(rand()*2)-1;
end
plot(x, y, color(m), 'LineWidth',2);
hold on
axis([0 100, -20 20])
end
end