Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please show the work in Python thank you ! Problem 3 (4pt) We repeat the above steps but now for the random variable M2N ,

Please show the work in Python thank you !

image text in transcribedimage text in transcribed
Problem 3 (4pt) We repeat the above steps but now for the random variable M2N , the time when the maximum is reached. Write a function that takes a random walk path of length 2N and evaluates the value of M2N on it. 1. Function: timeHitMax (. . . ) Input: . path: Realization of the random walk from the function randomWalk (2N) (Array of length 2N + 1) Output: . result: Realization of the random variable M2N (scalar) In [12]: def timeHitMax ( randomWalk) : ## WRITE YOUR OWN CODE HERE ## HINT: USE numpy . argmax( ) if randomWalk. ndim == 1: result = np. argmax ( randomWalk) if randomWalk. ndim == 2: result = np. argmax ( randomWalk, axis = 1) return result In [6] : ## TEST YOUR FUNCTION HERE path = randomWalk(20) print (path) timeHitMax (path) [0, 1, 2, 1, 0, -1, -2, -1, 0, -1, -2, -3, -4, -5, -6, -7, -6, -7, -8, -9, -8, -9, -10, -9, -8, -7, -8, -7, -6, -5, -6, -5, -4, -5, -4, -3, -2, -3, -4, -5, -4]2. Write a function sampleMaxTime that samples M paths of the random walk, runs timeHitMax on each of them and returns an Array of length M that contains the resulting empirical distribution of M2N . Even more amazingly, it turns out the limiting distribution of Man is again the arcsine distribution, i.e. the histograms of MEN and L2N should look very similar! Run your samp leMaxTime function with N=250 and M=10,000 simulations and plot the histogram of M2N . Modify the plotting code below as needed. As mentioned the shape of the histogram should look like the arcsine density above. [ ] : # COMPLETE/ MODIFY THE PLOT COMMANDS ACCORDINGLY N = 250 M = 10000 c= sampleMaxTime (N, M) # This has to be replaced by the simulated values for M_2N ! ! ! plt . figure (figsize=(10,5) ) pit. title("Normalized histogram for 10000 realisations of $M_{500}$") plt. hist(c, bins='auto', density='True' ) plt . legend ( ) pit . show( )

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

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions