Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This is not a difficult question. It just appears long. Please help. I need the MATLAB code for all 3 parts (seperately labeled) (a) Write
This is not a difficult question. It just appears long. Please help. I need the MATLAB code for all 3 parts (seperately labeled)
(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 (Urand,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 is > 0 and 0.1 andStep 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