Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Question 1: Make sure you set up your notebook to produce matplotlib plots and import the right modules, as well NumPy. Do that here. import
Question 1: Make sure you set up your notebook to produce matplotlib plots and import the right modules, as well NumPy. Do that here. import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes 3D import numpy as np %matplotlib inline Generate an array x that has n = 100 random numbers that are uniformly distributed over the interval [0, 1) . Look up how to use the uniform() submodule of numpy. random for this question. # generate array of 100 elements n = 100 # elements ahould be uniformly distributed random numbers # np.random.uniform() takes 3 parameters # 1 - start value (0) # 2 - end value (1) # 3 - number of values (n) x = np. random.uniform(0, 1, n) Question 2: We want to divide the numbers in the interval [0, 1) into equally spaced sub-intervals. For example, say we want to take an array of 100 numbers that have values greater than or equal to 0 and less than 1. We might like to divide these numbers into 4 equally spaced half-open sub-intervals: 0 to 0.25, 0.25 to 0.5, 0.5 to 0.75, and 0.75 to 1. Write a function named partition_array using loops and if statements that takes the array x along with the number S of sub-intervals as inputs and outputs (returns) a new list numentries_subintervals with S entries. Each entry in numentries_subintervals will contain the number of values from x within each of the sub-intervals. The function will also output a second list that contains the mid points of each corresponding sub-interval. Test it on the array generated in Question 1, use S = 5 subintervals, and print the function outputs to verify the results. NOTE: You can assume that your input array x will have values in the interval [0, 1). Your results should be something like the following (Your number of entries will vary slightly): The number of entries in the subintervals are [15, 18, 19, 26, 22] The subinterval mid points of the intervals are [0.1, 0.3, 0.5, 0.7, 0.9] # plot x to visualize plt. scatter(list (range(n)), x) # plot labels plt.xlabel('n') plt. y label('x') plt.show() Question 4: What do you observe as the value of n increases? Put your answer here Question 5: Write a function compute_average (from scratch) that computes and returns the average of the values in an array. Then, generate arrays of different lengths n where n takes the values from 110, 104,5 x 104, 10%, 5 x 10", 104,5 x 104, 10, 5 x 10", 10,5 x 109. The arrays contain random numbers that are uniformly distributed over the interval [0, 1). Basically, loop through these different values of n, for each n make a uniformly distributed array of length n. Compute the array average for each n. Plot this average value versus n using a log scale for the x-axis. Make sure to label the axes and give the plot a title. What do you observe as n increases? Look up information about the law of large numbers. def compute_average Write your observations of the behavior in the plot here
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started