Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
generating random numbers

Subject: generating random numbers

From: yugandhar ch

Date: 1 Feb, 2012 06:27:10

Message: 1 of 5

hi,
how to write a matlab code for generating random numbers for Pareto(two parameters) and triangular distribution.pl give detail answers
thanks

Subject: generating random numbers

From: Roger Stafford

Date: 1 Feb, 2012 19:54:10

Message: 2 of 5

"yugandhar ch" <yug_0203@rediffmail.com> wrote in message <jgalvu$kkb$1@newscl01ah.mathworks.com>...
> how to write a matlab code for generating random numbers for Pareto(two parameters) and triangular distribution.
- - - - - - - - - - -
  In the website
 http://en.wikipedia.org/wiki/Pareto_distribution
the two-parameter Pareto distribution shows you the cdf for it as:

 P(v<=x) = 1 - (xm/x)^alpha

You can generate it randomly using the inverse of this function along with matlab's 'rand' function as follows:

 x = xm./(rand(n,1)^(1/alpha));

{Note that 'rand' here gives equivalent results to 1-rand.)

  Or you can use the Statistical Toolbox's generalized Pareto function 'gprnd'.

  Similar remarks apply to the triangular distribution. At
 http://en.wikipedia.org/wiki/Triangular_distribution
it should be comparatively easy to devise the inverse of the cdf shown there so that this too can be generated using 'rand'. All you have to do is solve the quadratics there.

Roger Stafford

Subject: generating random numbers

From: yugandhar ch

Date: 2 Feb, 2012 06:47:10

Message: 3 of 5

"Roger Stafford" wrote in message <jgc592$ofk$1@newscl01ah.mathworks.com>...
> "yugandhar ch" <yug_0203@rediffmail.com> wrote in message <jgalvu$kkb$1@newscl01ah.mathworks.com>...
> > how to write a matlab code for generating random numbers for Pareto(two parameters) and triangular distribution.
> - - - - - - - - - - -
> In the website
> http://en.wikipedia.org/wiki/Pareto_distribution
> the two-parameter Pareto distribution shows you the cdf for it as:
>
> P(v<=x) = 1 - (xm/x)^alpha
>
> You can generate it randomly using the inverse of this function along with matlab's 'rand' function as follows:
>
> x = xm./(rand(n,1)^(1/alpha));
>
> {Note that 'rand' here gives equivalent results to 1-rand.)
>
> Or you can use the Statistical Toolbox's generalized Pareto function 'gprnd'.
>
> Similar remarks apply to the triangular distribution. At
> http://en.wikipedia.org/wiki/Triangular_distribution
> it should be comparatively easy to devise the inverse of the cdf shown there so that this too can be generated using 'rand'. All you have to do is solve the quadratics there.
>
> Roger Stafford

Subject: generating random numbers

From: yugandhar ch

Date: 2 Feb, 2012 06:53:10

Message: 4 of 5

"Roger Stafford" wrote in message <jgc592$ofk$1@newscl01ah.mathworks.com>...
> "yugandhar ch" <yug_0203@rediffmail.com> wrote in message <jgalvu$kkb$1@newscl01ah.mathworks.com>...
> > how to write a matlab code for generating random numbers for Pareto(two parameters) and triangular distribution.
> - - - - - - - - - - -
> In the website
> http://en.wikipedia.org/wiki/Pareto_distribution
> the two-parameter Pareto distribution shows you the cdf for it as:
>
> P(v<=x) = 1 - (xm/x)^alpha
>
> You can generate it randomly using the inverse of this function along with matlab's 'rand' function as follows:
>
> x = xm./(rand(n,1)^(1/alpha));
>
> {Note that 'rand' here gives equivalent results to 1-rand.)
>
> Or you can use the Statistical Toolbox's generalized Pareto function 'gprnd'.
>
> Similar remarks apply to the triangular distribution. At
> http://en.wikipedia.org/wiki/Triangular_distribution
> it should be comparatively easy to devise the inverse of the cdf shown there so that this too can be generated using 'rand'. All you have to do is solve the quadratics there.
>
> Roger Stafford

thanks Mr.Roger for your suggestion. In case of triangular dist ,the pdf is in intervals
then how to write cdf in a single function.I would be grateful to you if send the code
with regards,
yugandhar.

Subject: generating random numbers

From: Roger Stafford

Date: 2 Feb, 2012 20:23:16

Message: 5 of 5

"yugandhar ch" <yug_0203@rediffmail.com> wrote in message <jgdbsm$l18$1@newscl01ah.mathworks.com>...
> thanks Mr.Roger for your suggestion. In case of triangular dist ,the pdf is in intervals
> then how to write cdf in a single function.I would be grateful to you if send the code
- - - - - - - - -
  It is quite possible to write a single function in which the form of the function depends on some condition. In your case the one condition is whether the 'rand' value is less than the (c-a)/(b-a) value referred to in that Wikipedia article. With m-file functions, just use an if-else construction and with anonymous functions a logical inequality quantity (e.g., "@(x) (x>=0)*exp(x)+(x<0)*(sin(x)+1)" ).

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us