MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Triangular Distribution in Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg74271] Re: Triangular Distribution in Mathematica
  • From: "Valeri Astanoff" <astanoff at gmail.com>
  • Date: Thu, 15 Mar 2007 19:18:09 -0500 (EST)
  • References: <etb5v7$kho$1@smc.vnet.net>

On 15 mar, 11:08, Bob Hanlon <hanl... at cox.net> wrote:
> TriangularDistribution/:
>     PDF[TriangularDistribution[xmin_,xmode_,xmax_],x_]:=
>     2/(xmax-xmin)*(UnitStep[x-xmin]*(x-xmin)/(xmode-xmin)+
>           UnitStep[x-xmode]*((
>     xmax-xmin)*(x-xmode))/((xmax-xmode)*(xmin-xmode))-
>           UnitStep[x-xmax]*(xmax-x)/(xmax-xmode));
>
> TriangularDistribution/:
>   CDF[TriangularDistribution[xmin_,xmode_,xmax_],x_]:=
>   -(((xmax-xmode)*UnitStep[x-xmin]*(x-xmin)^2-(xmin-xmode)*UnitStep[
>     x-xmax]*(UnitStep[xmax-xmin]*(x-xmax)^2+(x-xmin)*(x-2*xmax+xmin)*
>                 UnitStep[xmin-xmax])-(
>                     xmax-xmin)*UnitStep[x-xmode]*(UnitStep[xmode-xmin]*(x=
-\
> xmode)^2+(x-xmin)*(x+xmin-2*xmode)*UnitStep[xmin-xmode]))/((xmax-
>                     xmin)*(xmax-xmode)*(xmin-xmode)))
>
> xmin=270;
> xmax=420;
> xmode=392;
>
> Plot[PDF[TriangularDistribution[xmin,xmode,xmax],x],{x,xmin-20,
>         xmax+20},PlotStyle->Red,PlotRange->All];
>
> Plot[CDF[TriangularDistribution[xmin,xmode,xmax],x],{x,xmin-20,
>         xmax+20},PlotStyle->Red,PlotRange->All];
>
> You could use Piecewise instead of UnitStep.
>
> Bob Hanlon
>
>
>
> ---- nege... at googlemail.com wrote:
> > Dear all,
>
> > Does any one know how to use triangular distribution in Mathematica?
> > Does any one have an add-in? Or a formula that works? I want to get
> > the PDF function, plot and the first four moments, mean, variance,
> > skew, kurtosis. I have the following parameters for the distribution
> > minimum value 270, maximum 415 and  likeliest or mode 392.
>
> > Thanking in Adavance,
>
> > Negede- Masquer le texte des messages pr=E9c=E9dents -
>
> - Afficher le texte des messages pr=E9c=E9dents -


A piecewise version :

TriangularDistribution::usage="TriangularDistribution[a, b, m]
represents
    the triangular distribution with range (a,b) and mode m ";

TriangularDistribution/:PDF[TriangularDistribution[a_,b_,m_],x_]:=
  (2*Piecewise[{{(a-x)/(a-m),a<m<b && a<x<m},
            {(b-x)/(b-m),a<m<b && m<x<b}},0])/(b-a)

TriangularDistribution /: CDF[TriangularDistribution[a_, b_,
m_],x_] :=
   Piecewise[{{0,x<=a},
   {(a - x)^2/((a - b)*(a - m)),a<=m<=b && a<=x<=m},
   {(a*(b - m) + b*(m - 2*x) + x^2)/((a - b)*(b - m)),a<=m<=b &&
m<=x<=b},
   {1,x>=b}},0];

TriangularDistribution/:Mean[TriangularDistribution[a_,b_,m_]]:=
    (a+b+m)/3;

TriangularDistribution/:Variance[TriangularDistribution[a_,b_,m_]]:=
    (a^2+b^2-b*m+m^2-a*(b+m))/18;

TriangularDistribution/:StandardDeviation[TriangularDistribution[a_,b_,m_]]=
:=

     Sqrt[(a^2+b^2-b*m+m^2-a*(b+m))/18];

TriangularDistribution/:Skewness[TriangularDistribution[a_,b_,m_]]:=
    (Sqrt[2]*(a+b-2*m)*(2*a-b-m)*(a-2*b+m))/
      (5*(a^2+b^2-b*m+m^2-a*(b+m))^(3/2));

TriangularDistribution/:Kurtosis[TriangularDistribution[a_,b_,m_]]:=
    12/5;

TriangularDistribution/:KurtosisExcess[TriangularDistribution[a_,b_,m_]]:=
=
    -3/5;





  • Prev by Date: Re: Initialization cell appearance
  • Next by Date: Re: Bug with Limit?
  • Previous by thread: Re: Triangular Distribution in Mathematica
  • Next by thread: Real/Comlex function problem with D