Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

MATLAB coding. RANDOM NUMBER GENERATOR help needed. PLEASE PROVIDE THE CODE TO ALL PARTS 2. Many computing applications require a source of random numbers. Although

image text in transcribedMATLAB coding. RANDOM NUMBER GENERATOR help needed. PLEASE PROVIDE THE CODE TO ALL PARTS

2. Many computing applications require a source of random numbers. Although no computer pro- gram (which is necessarily deterministic) can produce truly random numbers, programs can pro- duce pseudo-random numbers that provide a reasonably good approximation of random numbers. One simple and popular way to produce pseudo-random numbers is to use a linear congruential generator. It produces a sequence of random numbers Rk between 0 and m1 from the recurrence relation Rk+(aRkc mod m Here m is called the modulus, and a and c are positive integers called the multiplier and the increment. If m,a, and c are properly chosen, this algorithm can provide a decent pseudo-random number source. (a) Write a MatLab program that generates a vector of N pseudo-random numbers (where N is entered by the user) using the following form of the linear congruential generator: Rk+1 936Rk +1399) mod 6655 Mat Lab's mod (A,B) function can be used to calculate A modulus B To start up the generator, an initial number for Ri, called the seed, must be chosen. This can be any number between 0 and 11979 (the maximum value the generator can produce). A quick and dirty way to generate a different seed each time the program is run is to generate it from the time of day using the MatLab clock function. clock returns a 6-element vector containing the current date and time, and we can extract the minutes and seconds from this function and use them to create a 4-digit number with the following lines of code: MinSec-fix(clock); seed 100 MinSec (5) MinSec (6) Finally, it's standard practice to have uniformly distributed random numbers be confined to the interval [0,1]. Have your program do this to your generated values by dividing each value by the maximum possible random value (6655 for our generator) that can be generated. Print out the results you obtain for N 50 (b) To see if the random numbers generated are more or less uniformly distributed over the interval [0,1], add code to your program that creates a plot in which each random value is plotted along the X axis with a cross. If your vector of random numbers is called Urand, the plot is easily created with the code Y-ones (size(Urand)); plot (Urana, Y , , x' ) (c) To get a somewhat more quantitative measure of whether the random numbers are uniformly distributed, add code to your program that sorts the random values into bins by counting how many N values are in the interval [0,0.1], how many are in (0.1,0.2], how many are in (0.2,0.3], etc. To do this, first create a 10-element vector called Bin, having values of zero for each element. Then write a for loop that looks at each random value, and, using a series of if . . . elseif. . . elseif blocks, increments the appropriate element of Bin. For example if a random value is0 and0.1, Bin1) should be incremented, if it is 0.1 and 0.2, Bin (2) should be incremented, etc Have your program print out the number of random values that fall into each bin (but not all the values themselves!), and examine your results for N-50, N500, and N 5000 values. Do the random numbers appear to be uniformly distributed between 0 and 1? I need the MATLAB code for parts A, B and C please

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 Database Management

Authors: Fred R. McFadden, Jeffrey Slater, Mary B. Prescott

5th Edition

0805360549, 978-0805360547

More Books

Students also viewed these Databases questions

Question

6. Identify characteristics of whiteness.

Answered: 1 week ago

Question

9. Explain the relationship between identity and communication.

Answered: 1 week ago