Finished Homework2.

This commit is contained in:
SJ2050cn
2021-10-29 23:58:21 +08:00
parent b34436ca5c
commit 19681c61d6
28 changed files with 325 additions and 0 deletions
@@ -0,0 +1,24 @@
'''
Author: SJ2050
Date: 2021-10-29 19:56:04
LastEditTime: 2021-10-29 22:57:17
Version: v0.0.1
Description: Solution for homework2.3.
Copyright © 2021 SJ2050
'''
import numpy as np
from matplotlib import pyplot as plt
if __name__ == '__main__':
ts = np.array([i for i in range(1000)])
xs = np.zeros(1000)
ys = np.zeros(1000)
xs[0] = np.random.rand(1)*2-1
ys[0] = np.random.rand(1)*2-1
for i in range(1, 1000):
xs[i] = xs[i-1]+np.random.rand(1)*2-1
ys[i] = ys[i-1]+np.random.rand(1)*2-1
plt.plot(xs, ys)
plt.show()
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

@@ -0,0 +1,11 @@
# 2.3 模拟一个醉汉在二维空间上的随机漫步
## (1). 解题思路
假设醉汉每一步的大小在`x``y`轴上的投影不超过1,在每个时刻,在`x``y`方向上都会生成一个[-1, 1]的数,然后与时刻的位置进行叠加,并把每个时刻的位置记录下来,最后就可以绘制出醉汉在二维空间上的随机漫步。
## (2). 运行结果
![](images/result.png)