Senin, 28 September 2009

Tugas 2 : Macam-macam Fungsi Distribusi

1. DISTRIBUSI EKSPONSIAL (lamda)
Function Eksponensial (beta : double) : double;
Var u : double;
Begin
   u := random;
   Eksponensial := -beta * ln(u);
End;

2. DISTRIBUSI UNIFORM (a,b)
Function Uniform (a,b : double) : double;
Var u : double;
Begin
  u:= random;
   Uniform := (b-a) * u + a;
End;

3. DISTRIBUSI NORMAL  (µ, sigma)
Procedure Normal (mean,variance : double ; Var z1,z2 : double);
Var u1,u2,v1,v2,w,y,x1,x2 : double;
Begin
   Repeat
      u1 := random;
      u2 := random;
      v1 := 2 * u1 - 1;
      v2 := 2 * u2 - 1;
      w := sqr(v1) + sqr(v2);
      if w <= 1 then
         begin
            y := sqrt ((-2*ln(w))/w);
            x1 := v1 * y;
            x2 := v2 * y;
            z1 := sqrt (variance) * x1 + mean;
            z2 := sqrt (variance) * x2 + mean;
         end
   Until w <= 1;
End;

4. DISTRIBUSI LOGNORMAL
procedure lognormal (mean,varr : double;
Var  zln1,zln2 : double);
Var y1, y2 : double;
begin
    Normal (mean,varr,y1,y2);
    zln1 := exp(y1);
    zln2 := exp(y2);
end;

5. DISTRIBUSI T-STUDENT


function tdistribution(m:integer):double;
{ created :
         based on Principles of Random Variate Generation
                   by John Dagpunar, 1988
         published by Claredon Press - OXFORD
   please check if any other theory of t-distribution }
Label r2;
Var v,x,r,s,c,a,f,g,mm : real;
begin
  mm:=0;
  if m < 1 then
  begin
     writeln('impermissible degrees of freedom.');
     halt;
  end;
  if (m <> mm) then
  begin
     s:=m;
     c:=-0.25*(s+1);
     a:=4/power((1+1/s),c);
     f:=16/a;
     if m>1 then
     begin
       g:=s-1;
       g:=power(((s+1)/g),c)*sqrt((s+s)/g);
     end else
            g := 1;
     mm:=m;
  end;
r2:repeat
    r:=random;
  until r > 0.0;
  x:=(2*random-1)*g/r;
  v:=x*x;
  if (v>(5-a*r)) then
  begin
     if ((m>=3) and (r*(v+3)>f)) then goto r2;
     if (r>power((1+v/s),c)) then goto r2;
  end;
  tdistribution :=x;
end;
begin
   tipe11[1]:=0.2;
   tipe11[1]:=0.3;
   tipe11[1]:=0.5;
   tipe11[1]:=0.8;
   tipe11[1]:=1.0;
end.

6. DISTRIBUSI WEIBULL
Function Weibull (alfa,beta: double) : double;
Var u,z : double;
Begin
   u := random;
   z := -ln(v);
   Weibull := beta * exp (ln(z)/alfa);
End;




0 komentar:

Posting Komentar

 

Blog Es Campur Copyright © 2009 Girlymagz is Designed by Bie Girl Vector by Ipietoon