import numpy as np
import random
import matplotlib.pyplot as plt
def randomWalk(L):
# S is a 2d array where x = row1= S[0][:], y = row2 = S[1][:]
S = np.zeros(shape=(2,L+1))
directions = [1,2,3,4]
for i in range(1, L+1):
direction = np.random.choice(directions)
if direction == 1:
S[0][i] = S[0][i-1] + 1; S[1][i] = S[1][i-1] # go right
elif direction == 2:
S[0][i] = S[0][i-1] - 1; S[1][i] = S[1][i-1] # go left
elif direction == 3:
S[0][i] = S[0][i-1]; S[1][i] = S[1][i-1] + 1 # go up
else:
S[0][i] = S[0][i-1]; S[1][i] = S[1][i-1] - 1; # go down
samplePath = S
return samplePath
n = 100;
path = randomWalk(2*n)
print(path)
x = path[0][:]; y = path[1][:];
plt.figure(1)
plt.plot(x,y,'-')
plt.ylabel('y')
plt.xlabel('x')
plt.show()


COMMENT DOWN FOR ANY QUERY RELATED TO THIS ANSWER,
IF YOU'RE SATISFIED, GIVE A THUMBS UP
~yc~
Code in Python Problem 1 (2 Points) 1. Write a function randomWalk(.. .) which simulates one path (or trajectory) of a s...
Code in Python
Problem 1 (2 Points) 1. Write a function randomWalk(.. .) which simulates one path (or trajectory) of a simple symmetric random walk with 2N time steps (i.e. from 0,1,2,...,2N) starting at So-0 nput: lengthofRandomWalk2N Output: samplePath: Array of length 2N+1 with the entire path of the random walk on 0,1,2,..,2N In def randomwalk(lengthofRandomwalk): ## WRITE YOUR OWN CODE HERE # HINT: USE np. random . choice ( ) TO SIMULATE THE INCREMENTS return samplePath In [ ]:...
This problem investigates how you can use random numbers to simulate a computer dice game write a function called twooice that simulates the rolling of two sik-sided dice. The function takes no inputs. Instead, it generates two random integers between 1 and 6, and output their sum. You may submit your work as many times as you want Try to get 100%) Your Function MATLAB Documentation Reset Code to call your function C Reset 1s-tuoDice ss-twoDice
This problem investigates how...
Write a python function that returns a list or array of tuples containing every permutation of numbers 1 to n. For example: permutate(1): [(1,)] permutate(2): [(1, 2), (2, 1)] permutate(3): [(1, 2, 3), (1, 3, 2), (3, 1, 2), (3, 2, 1), (2, 3, 1), (2, 1, 3)] #here is some starting code def permutate(n): result = [] return result
#PYTHON#
In this exercise you will write code which loads a collection of
images (which are all the same size), computes a pixelwise average
of the images, and displays the resulting average.
The images below give some examples that were generated by
averaging "100 unique commemorative photographs culled from the
internet" by Jason Salavon. Your program will do something
similar.
Write a function in the cell below that loads in one of the sets
of images and computes their average....
please use python thanks will rate!!
x + Run C Code Validate Implement the function step_random_walk_20(x_coords, Y_coords) below, which should take two arrays of equal length containing the x-andy- coordinates for some number of particles. We'll use a very simple random walk algorithm • For each particle, choose a random angle between 0 and 2 • The particle moves by 1 unit of distance in the direction given by d.o. It is displaced by (Ax, Ay) (cos, sino). We'll do...
Python: P2 Write a function that reverses a python list using recursion (Chapter 6-3 in our textbook) E.g.: Input: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0] Output: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] Constraints: - List elements are integers - The function should return a reversed array, not print its elements You may use the following code as template: def reverse(my_list, index = None): # your code here
need help with matLab
Question 1 (20 Points) Write a well-documented MATLAB script hmwk7Q1.m that simulates tossing 100 coins into a unit square. As shown in the scatter plot. Location of Simulated Coins In Unit Square 1 o0 Ooo 05 04 03 02 oo 0.1 2 03 4 05 07 1 xpostion Hmwk7Q1.fig Consider organizing your MATLAB script into the following sections. % housekeeping (performs clearing of figures, workspace, and command lines) % Initialize the Number of Coins To Simulate...
python program Use the provided shift function to create a caesar cipher program. Your program should have a menu to offer the following options: Read a file as current message Save current message Type in a new message Display current message "Encrypt" message Change the shift value For more details, see the comments in the provided code. NO GLOBAL VARIABLES! Complete the program found in assignment.py. You may not change any provided code. You may only complete the sections labeled:#YOUR...
Use Python 3 in Jupyter Write a function called countUnique that has one parameter which is a NumPy array. The array will be a list of integers with many repeated values. The function should count how many times each unique integer appears and return the counts. For example, if it is given the array array([3, 3, 3, 1, 1, 3, 1, 1, 3, 2]), it should return the counts [(1, 4), (2, 1), (3, 5)] since 1 appears 4 times,...
python
Write a function that takes as input a single integer parametern and computes the nth Fibonacci Sequence number The Fibonacci sequence first two terms are 1 and 1(so, if n - 2 your function should return 1). From there, the previous two values are summed to come up with the next result in the sequence 1.1,2,3,5,8,13, 21, 34, 55, etc.) For example, if the input is 7 then your function should return 13 26561.1615880 1 def Fibonacci(n): # your...