Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

What is wrong with the python code below? How do I fix it ? def simulate _ escape _ with _ trajectory ( M )

What is wrong with the python code below? How do I fix it?def simulate_escape_with_trajectory(M):
box_length =50
step =2
escapes =0
last_trajectory =[]
for i in range(M):
x_corr, y_corr = box_length //2, box_length //2
trajectory =[(x_corr, y_corr)] #Store initial position
for t in range(600):
u = np.random.uniform(low =0, high =1)
if u <0.25:
x_corr -= step
elif u <0.5:
x_corr += step
elif u <0.75:
y_corr += step
else:
y_corr -= step
x_corr = max(0, min(box_length, x_corr))
y_corr = max(0, min(box_length, y_corr))
trajectory.append((x_corr, y_corr)) #Store current position
if y_corr >= box_length and 20<= x_corr <=30:
escapes +=1
#print("escaped!", i)
last_trajectory = trajectory #Update last trajectory
break
probability = escapes / M
return escapes, probability, last_trajectory
attempts = np.linspace(10,1000,19)
data ={"attempts": [], "escapes": [], "probability": []}
for M in attempts:
escapes, probability, last_trajectory = simulate_escape_with_trajectory(M)
data["attempts"].append(M)
data["escapes"].append(escapes)
data["probability"].append(probability)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What are your businesss key cost drivers?

Answered: 1 week ago

Question

This type of muscle is voluntary, meaning you can control it

Answered: 1 week ago