Rayleigh Distribution. The Rayleigh distribution is another random number distribution that appears in many practical problems. A Rayleighdistributed 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 \(\left(n_{1}\right.\) and \(\left.n_{2}\right)\), and perform the following calculation. $$ r=\sqrt{n_{1}^{2}+n_{2}^{2}} $$ a. Create a function rayleigh \((\mathrm{n}, \mathrm{m})\) that returns an \(\mathrm{n} \mathrm{x} \mathrm{m}\) array of Rayleigh-distributed random numbers. If only one argument is supplied [rayleigh \((\mathrm{n})\) ], the function should return an \(\mathrm{n} \times \mathrm{n}\) array of Rayleigh- distributed random numbers. Be sure to design your function with input argument checking and with proper documentation for the MATLAB help system. b. Test your function by creating an array of 20,000 Rayleigh-distributed random values and plotting a histogram of the distribution. What does the distribution look like? c. Determine the mean and standard deviation of the Rayleigh distribution.

Short Answer

Expert verified
In this exercise, we implemented a function rayleigh(n, m) that returns an n x m array of Rayleigh-distributed random numbers using the formula \(r = \sqrt{n_1^2 + n_2^2}\), where \(n_1\) and \(n_2\) are normally distributed random values. We tested the function by creating an array of 20,000 Rayleigh-distributed random values and plotted a histogram, which showed a unimodal distribution with an early increase towards the mode and a gradual decrease. The mean and standard deviation of the Rayleigh distribution were calculated as \(\mu \approx 1.2533\) and \(\sigma_r \approx 0.6654\), respectively.

Step by step solution

01

Create the function rayleigh(n, m)

Here, we create a function named rayleigh that receives two parameters, n and m. The function should return n x m Rayleigh-distributed random numbers. The Rayleigh-distributed random value r can be obtained by the formula: \( r = \sqrt{n_1^2 + n_2^2} \), where \(n_1\) and \(n_2\) are two normally distributed random numbers. ```MATLAB function r = rayleigh(n, m) if nargin == 1 m = n; end if ~isscalar(n) || ~isscalar(m) || n < 1 || m < 1 error('Inputs must be positive scalar integers.'); end n1 = randn(n, m); n2 = randn(n, m); r = sqrt(n1.^2 + n2.^2); end ```
02

Test the function

We will now test the rayleigh function by creating an array of 20,000 Rayleigh-distributed random values. Then, we will plot a histogram of the array. ```MATLAB r_values = rayleigh(20000, 1); hist(r_values, 100); xlabel('Value'); ylabel('Frequency'); title('Histogram of Rayleigh-distributed random values'); ``` By running this code, we get a histogram representing the distribution of Rayleigh random values. The distribution looks like a unimodal distribution with an early increase towards the mode and then a gradual decrease.
03

Determine the mean and standard deviation

According to the definition of the Rayleigh distribution, if \(n_1\) and \(n_2\) are normally distributed random variables with mean 0 and standard deviation \(\sigma\), the mean and the standard deviation of the Rayleigh distribution can be calculated as follows: Mean: \(\mu = \sigma\sqrt{\frac{\pi}{2}}\) Standard deviation: \(\sigma_r = \sigma\sqrt{2 - \pi/2}\) Considering that \(n_1\) and \(n_2\) are standard normal random variables (mean = 0 and standard deviation = 1), the mean and standard deviation of the Rayleigh distribution are: Mean \(\mu = \sqrt{\frac{\pi}{2}} \approx 1.2533\) Standard deviation \(\sigma_r = \sqrt{2 - \pi/2} \approx 0.6654\) Alternatively, we can use the r_values array to empirically calculate the mean and standard deviation: ```MATLAB mean_r = mean(r_values); std_r = std(r_values); ``` The values obtained will be close to the theoretical mean and standard deviation.

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

Key Concepts

These are the key concepts you need to understand to accurately answer the question.

MATLAB Programming
MATLAB is an extensively used programming platform for engineers and scientists to analyze data, develop algorithms, and create models. One of MATLAB's strengths is its vast collection of built-in functions that allow quick and efficient handling of mathematical computations. For instance, generating random numbers or employing built-in functions like randn, sqrt, and plotting functions. When writing MATLAB functions, best practices suggest implementing input validation and documentation to make the code robust and user-friendly. For instance, the rayleigh function in this exercise includes argument checking with nargin and error to ensure valid input, which helps prevent unexpected behavior and makes the function more reliable and easier to understand.
Random Number Generation
Random number generation is a fundamental aspect in simulations, statistical sampling, and various computational algorithms. In MATLAB, normal random numbers can be generated using the function randn, which produces values with a mean of 0 and a standard deviation of 1, following the standard normal distribution.

In this exercise, we create Rayleigh-distributed random numbers by transforming standard normal variables. The transformation involves square and addition operations followed by the square root function, yielding values that are Rayleigh distributed. The exercise emphasizes the way that distributions can be manipulated and transformed, which is a key concept in probability and statistics.
Histogram Plotting
A histogram is a graphical representation that breaks the data into bins and displays the frequency of data points within each bin. In MATLAB, the hist function is used to create histograms, vital for visualizing the underlying distribution of data sets. When plotting histograms of generated data, it can reveal the typical shape of the distribution, which, for a Rayleigh-distributed set, is unimodal showing a peak and then a gradual tail-off. Visualizing the Rayleigh distribution can help students gain intuition about how randomly generated datasets can conform to theoretical expectations.
Statistical Mean and Standard Deviation
The mean and standard deviation are fundamental statistical measures that describe the central tendency and spread of a data set, respectively. In the context of Rayleigh distribution, we use specific formulas to determine these measures, which differ from those of normal distribution due to the nature of the transformation applied to the normally distributed variables. Understanding these statistical measures is key for interpreting the generated Rayleigh-distributed data. MATLAB simplifies this process allowing users to compute these descriptors empirically using the mean and std functions, which validate the theoretical calculations based on the parameters of the underlying normal distribution.

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Sort with Carry. It is often useful to sort an array are1 into ascending order, while simultancously carrying along a second array arr2. In such a sort, each time an element of array arrl is exchanged with another element of arr1, the corresponding elements of array arr2 are also swapped. When the sort is over, the elements of array arri are in ascending order, whereas the elements of array arr 2 that were associated with particular elements of array arrl are still associated with them. For example, suppose we have the following two arrays. \(\begin{array}{ccc}\text { Element } & \text { arr1 } & \frac{\operatorname{arc} 2}{1 .} \\ 1 . & 6 . & 0 . \\ 2 . & 1 . & 10 . \\\ 3 . & 2 . & 10 .\end{array}\) After sorting array arrl while carrying along array arr2, the contents of the two arrays will be \(\begin{array}{ccc}\text { Element } & \text { arr1 } & \text { are2 } \\ 1 . & 1 . & 0 . \\ 2 . & 2 . & 10 . \\ 3 . & 6 . & 1 .\end{array}\) Write a function to sort one real array into ascending order while carrying along a second one. Test the function with the following two 9 -element arrays. $$ \begin{aligned} &a=[-1, \quad 12, \quad-6, \quad 17, \quad-23,0,5, \quad 1,-1]: \\ &b=[-31,101,36,-17, \quad 0,10,-8,-1,-1]= \end{aligned} $$

Use the Help Browser to look up information about the standard MATLAB function sortrows and compare the performance of sortrows with the sort-with-carry function created in the previous exercise. To do this, create two copies of a \(1000 \times 2\) element array containing random values, and sort column 1 of each array while carrying along column 2 using both functions. Determine the execution times of each sort function using tic and toe. How does the speed of your function compare with the speed of the standard function sorerows?

Probability of Detection \(\left(P_{2}\right)\) versus Probability of False Alarm \(\left(P_{\text {a }}\right)\). The signal strength returned by a radar target usually fluctuates over time. The target will be detected if its signal strength exceeds the detection threshold for any given look. The probability that the target will be detected can be calculated as $$ P_{i=}=\frac{\text { Number of Target Detections }}{\text { Total Number of Looks }} $$ Suppose that a specific radar looks repeatedly in a given direction. On cach look, the range between \(10 \mathrm{~km}\) and \(20 \mathrm{~km}\) is divided into 100 independent range samples (called range gates). One of these range gates contains a target whose amplitude has a normal distribution with a mean amplitude of 7 volts and a standard deviation of I volt. All 100 of the range gates contain system noise with a mean amplitude of 2 volts and a Rayleigh distribution. Determine both the probability of target detection \(P_{d}\) and the probability of a false alarm \(P_{1,}\) on any given look for detection thresholds of \(8.0,8.5,9.0,9.5,10.0,10.5,11.0,11.5\), and \(12.0 \mathrm{~dB}\). What threshold would you use for detection in this radar? (Hint: Perform the experiment many times for each threshold and average the results to determine valid probabilities.)

Write three MATLAB functions to caiculate the hyperbolic sine, cosine, and tangent functions. $$ \sinh (x)=\frac{e^{x}-e^{-x}}{2}, \cosh (x)=\frac{e^{x}+e^{-x}}{2}, \tanh (x)=\frac{e^{x}-e^{-x}}{e^{x}+e^{-x}} $$ Use your functions to plot the shapes of the hyperbolic sine, cosine, and tangent functions.

Write a function that uses function randomo to generate a random value in the range [low, high), where low and high are passed as calling arguments. Make random0 a private function called by your new function.

See all solutions

Recommended explanations on Psychology Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free