[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] gauss fordelt rand()



On Thu, 26 Apr 2001, Sune Fischer wrote:

> Er der nogen der kan huske, hvordan man får ligefordelingen lavet om til fx. en gaussfordeling?

Man bruger Box-Muller metoden. Nedenstående stykke kode kan gøre det:

void RandNormDist(double sigma, double mean, double *x, double *y) {

  double u1, u2, fac, r;

  do {
    u1=2.0*RandUnit()-1.0;
    u2=2.0*RandUnit()-1.0;
    r=u1*u1+u2*u2;
  } while ((r>1.0) || (r==0.0));
  fac=sqrt(-2.0*log(r)/r);
  u1*=fac;
  u2*=fac;
  *x=mean+sigma*u1;
  *y=mean+sigma*u2;
} /* RandNormDist */

RandNormDist giver dig to normalt fordelte tal (x og y). Parametrene sigma
og mean er spredning og middel.

RandUnit returnerer et ligefordelt tal i intervallet [0.0;1.0[. HVis du er
interesseret, har jeg et lille primitivt bibliotek til at generere
tilfældige tal (ovenstående kode er klippet fra det bibliotek).

Kneth

-- 
Kenneth Geisshirt, Ph.D.   mailto:sslug@sslug
Grøndals Parkvej 2A, 3.    http://kenneth.geisshirt.dk
DK-2720 Vanløse                        +45 38 87 78 38



 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:08 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *