Atinesh
Atinesh

Reputation: 1920

How to draw random number from a Cauchy Distribution in Matlab

I know random number can be drawn from a Normal Distribution as follows

normrnd(mu, sd)

where mu=mean and sd=standard deviation

But how can we draw a random number from Cauchy Distribution with given location parameter and scale parameter, as there is no built-in function available in matlab. For more information about Cauchy Distribution see Link1 and Link2.

Upvotes: 1

Views: 1752

Answers (2)

Alessandro Trigilio
Alessandro Trigilio

Reputation: 326

From the explanation given here, you can get a Cauchy distributed random number from an uniform random number using the following transformation:

r = tan(pi*(rand()-0.5))

Upvotes: 0

qbzenker
qbzenker

Reputation: 4652

You can always write your own function, if you know the cdf.

function x = cauchy_dist(location_parameter, scale_parameter)
p_cdf = rand(); %uniform random from 0->1, since cdf by definition 0->1
x = location_parameter + scale_parameter*tan(pi*(p_cdf-0.5)); %solve cdf eqn for x

Upvotes: 1

Related Questions