0% found this document useful (0 votes)
22 views5 pages

Python Lab 12 @333

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views5 pages

Python Lab 12 @333

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

SRM IST

Faculty of Engineering and Technology


Department of Electronics and Communication Engineering
18ECE3201J PYTHON AND SCIENTIFIC PYTHON
Fifth Semester, 2021-22 (Odd Semester)

LABORATORY REPORT COVER SHEET

Name : A. Jagadeesh Reddy

Register Number : RA1911004010333

Day / Session : Day Order 3 / A.N

Venue : Google Meet

Title of the Experiment : Random Walk in One Space Dimension

Date of Performance : 04/10/2021

Date of Submission : 10/10/2021

Particulars Max. Marks Marks Obtained

Pre Lab 05

Program 10

Post Lab 05

Output Verification 15

Viva 05

Total 40

REPORT VERIFICATION

Staff Name : Dr. Shyamal Mondal


Signature :
12. Random Walk in One Space Dimension

Aim(s) /Flow chart/Algorithm


Aim / Objective. To Random walk in one space dimensions and perform the program in
Jupyter Notebook.
Program and Input Data
Write Python Code & also Few input data. Include all data tables and/or observation.

Program: Random walk in one space dimensions

Program:

import numpy as np
import matplotlib.pyplot as plt
def Randwalk(n):

x = 0
y = 0

time = [x]
position = [y]

for i in range (1,n+1):


move = np.random.uniform(0,1)

if move < 0.5:


x += 1
y += 1

if move > 0.5:


x += 1
y += -1

time.append(x)
position.append(y)

return [time,position]
Randwalk1 = Randwalk(1000)
Randwalk2 = Randwalk(1000)
Randwalk3 = Randwalk(1000)
plt.plot(Randwalk1[0],Randwalk1[1],'r-', label = "Randwalk1")
plt.plot(Randwalk2[0],Randwalk2[1],'g-', label = "Randwalk2")
plt.plot(Randwalk3[0],Randwalk3[1],'b-', label = "Randwalk3")
plt.title("1-D Random Walks")
plt.legend(loc='upper center', bbox_to_anchor=(0.5,-0.1),
fancybox=True, shadow=True)
plt.show()

Output:
PRE-LAB
1) Define import random ? How do you do Random walk?
POST LAB
1) Statement of the output of the following Python code is either 1 or 2 ?

Results and Conclusion


Hence, random walk in space dimensions was simulated using numpy and matplotlib. The
code was run successfully and the output was verified.

You might also like