Warning: foreach() argument must be of type array|object, bool given in /var/www/html/web/app/themes/studypress-core-theme/template-parts/header/mobile-offcanvas.php on line 20

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

Derivative in the Presence of Noise. We will now explore the effects of input noise on the quality of a numerical derivative. First, generate an input vector containing 100 values of the function \(\sin x\) starting at \(x=0\), using a step size \(\Delta x\) of \(0.05\), just as you did in the previous problem. Next, use function randomo to generate a small amount of random noise with a maximum amplitude of \(\pm 0.02\), and add that random noise to the samples in your input vector (see Figure 5.8). Note that the peak amplitude of the noise is only \(2 \%\) of the peak amplitude of your signal, since the maximum value of \(\sin x\) is 1. Now take the derivative of the function using the derivative function that you developed in the last problem. How close to the theoretical value of the derivative did you come?

Derivative of a Function. The derivative of a continuous function \(f(x)\) is defined by the equation $$ \frac{d}{d x} f(x)=\lim _{\Delta x=0} \frac{f(x+\Delta x)-f(x)}{\Delta x} $$ In a sampled function, this definition becomes $$ f^{\prime}\left(x_{i}\right)=\frac{f\left(x_{i+1}\right)-f\left(x_{i}\right)}{\Delta x} $$ where \(\Delta x=x_{i+1}-x_{i}\) Assume that a vector vect contains nsamp samples of a function taken at a spacing of \(d x\) per sample. Write a function that will calculate the derivative of this vector from Equation (5.12). The function should check to make sure that \(\mathrm{dx}\) is greater than zero to prevent divide-by-zero errors in the function. To check your function, you should generate a data set whose derivative is known, and compare the result of the function with the known correct answer. A good choice for a test function is \(\sin x\). From elemen\(\operatorname{tary}\) calculus, we know that \(\frac{d}{d x}(\sin x)-\cos x\). Generate an input vector containing 100 values of the function \(\sin x\) starting at \(x=0\) and using a step size \(\Delta x\) of \(0.05\). Take the derivative of the vector with your function, and then compare the resulting answers to the known correct answer. How close did your function come to calculating the correct value for the derivative?

Cross Product. Write a function to calculate the cross product of two vectors \(\mathbf{V}_{1}\) and \(\mathbf{V}_{2}\) \(\mathbf{V}_{1} \times \mathbf{V}_{2}=\left(V_{y 1} V_{x 2}-V_{v 2} V_{21}\right) \mathbf{i}+\left(V_{21} V_{x 2}-V_{22} V_{x 1}\right) \mathbf{j}+\left(V_{41} V_{v 2}-V_{x 2} V_{v 1}\right) \mathbf{k}\) where \(\mathbf{V}_{1}=V_{x 1} \mathbf{i}+V_{x 1} \mathbf{j}+V_{z 1} \mathbf{k}\) and \(\mathbf{V}_{2}=V_{x 2} \mathbf{i}+{y_{12}} \mathbf{j}+y_{x 2} \mathbf{k}\). Note that this function will return a real array as its result. Use the function to calculate the cross product of the two vectors \(V_{1}=[-2,4,0.5]\) and \(V_{2}=\) \([0.5,3,2]\).

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?

Read Traffic Density. Function random0 produces a number with a uniform probability distribution in the range \([0.0,1.0)\). This function is suitable for simulating random events if each outcome has an equal probability of occurring. However, in many events the probability of occurrence is not equal for every event, and a uniform probability distribution is not suitable for simulating such events. For example, when traffic engineers studied the number of cars passing a given location in a time interval of length \(t\), they discovered that the probability of \(k\) cars passing during the interval is given by the equation $$ P(k, t)=e^{-\lambda t} \frac{(\lambda t)^{4}}{k !} \text { for } t \geq 0, \lambda>0, \text { and } k=0,1,2, \ldots $$ This probability distribution is known as the Poisson distribution: it occurs in many applications in science and engineering. For example, the number of calls \(k\) to a telephone switchboard in time interval \(t\), the number of bacteria \(k\) in a specified volume \(t\) of liquid, and the number of failures \(k\) of a complicated system in time interval \(t\) all have Poisson distributions. Write a function to evaluate the Poisson distribution for any \(k, t\), and A. Test your function by calculating the probability of \(0,1,2, \ldots, 5\) cars passing a particular point on a highway in I minute, given that \(\lambda\) is \(1.6\) per minute for that highway. Plot the Poisson distribution for \(t=1\) and \(\lambda=1.6\).

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