How to generate samples from a cauchy distribution

Illustration
Erol - 2022-06-09T12:02:02+00:00
Question: How to generate samples from a cauchy distribution

For an assignment I have to draw samples of different sizes from a Cauchy distribution in order to show that as the sample size increases, the mean does not tend to any number (therefore the mean does not exist). However, I have been having trouble trying to figure out how to properly create my Cauchy distribution. Knowing that a cauchy distribution is simply a variable computed using the ratio of two independent standard normal variables, I created two standard normal variables and then divided them to create this new Cauchy variable. I then found the sample mean, and repeated the process for sample sizes of 10, 100, 500, 1000, 5000, and 10,000.     The following code is the same process that I used for each sample size: a_c1= randn(10,1) a_c2= randn(10,1) a_c1ovrc2=a_c1/a_c2 a_c1ovrc2( :, ~any(a_c1ovrc2,1) )= [] %in order to delete all the unnecessary zero columns(I don't understand why they were created in the first place) a_c1ovrc2_m = mean(a_c1ovrc2) The above table are the values i obtained after completing each operation separately. I don't feel like this accurately shows that the Cauchy distribution has no mean. Any advice as to what I might be doing wrong would be sincerely appreciated!

Expert Answer

Profile picture of Kshitij Singh Kshitij Singh answered . 2025-11-20

a_c1ovrc2( :, ~any(a_c1ovrc2,1) )= []
"in order to delete all the unnecessary zero columns(I don't understand why they were created in the first place)"
They came from the preceding line
 
a_c1ovrc2=a_c1/a_c2;

HINT: See

doc ./  % follow links to "Arithmetic Operators" at bottom

After perusing these, all should become clear...


Not satisfied with the answer ?? ASK NOW

Get a Free Consultation or a Sample Assignment Review!