For each of the problems in this lab assignment, write a separate MATLAB file. T
ID: 3832307 • Letter: F
Question
For each of the problems in this lab assignment, write a separate MATLAB file. The name of each m-file and function must be exactly as specified in the corresponding problem statement. Submit your files by uploading to Blackboard before the due date.
Filename: rayleigh .m MAE 1090 Lab11 1.m The Rayleigh distribution is a random number distribution that appears in many practical problems. A Rayleigh-distributed random value can be created by taking the square root of the sum of the squares of two normally distributed random values. In other words, to generate a Rayleigh-distributed random value r, get two normally distributed random values between 0 and 1 (n1 and n2), and perform the following calculation: ni n Write a MATLAB function rayleigh m with the following syntax: r rayleigh (n, m) that returns annx m array of Rayleigh-distributed random numbers. If only one argument is supplied [rayleigh(n), the function should return an n x n array of Rayleigh-distributed radom numbers. Be sure to design your function with input argument checking and with proper documentation for the MATLAB help system. Then, write an m-file (MAE1090 Lab11 1.m) to test your function by creating an array of 200,000 Rayleigh-distributed random values and plotting a histogram of the distribution. Be sure to include a title and axis labels.Explanation / Answer
Code :
function r = rayleigh(m,n)
if nargin<2
n1 = m*m;
else
n1 = m*n;
end
for i=1:n1
a = rand
b = rand
r(i) = sqrt(a.^2 + b.^2);
end
end
r =
Columns 1 through 8:
0.27174 1.02261 1.00560 0.65788 0.60685 0.30060 0.71851 0.39925
Columns 9 through 16:
0.50245 0.31900 0.54251 1.02753 0.92631 0.99053 1.13982 0.87214
for second part you just have to call the function histogram(X), where X is the array of values that you want to plot.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.