All pastes #188296 Raw Edit

Anonymous

public cpp v1 · immutable
·published 2006-10-01 23:57 UTC
rendered paste body
//Paragwgh tyxaiwn arithmwn kanonikhs katanomhs me Monte-Carlo methodo.//To aoristo oloklhrwma ths f(x):Gauss den yparxei kai efarmozw monte-carlo.//Me anakateu8unsh mporeis na pareis to arxeio pou 8es twra. Ta mhnumata pane sto stderr, ta data sto stdout.#include<iostream>#include<cstdlib>#include<cmath>#include<time.h>using namespace std;int main(){     const int a=0,b=1000;  double x,y,f,m,s;  int i=0,j;  cerr<<"\n";  cerr<<" PARGWGH TYXAIWN ARITHMWN KANONIKHS KATANOMHS "<<"\n";  cerr<<"\n";  cerr<<"   Dwse thesh koryfhs:"<<"\n";  cin>>m;  cerr<<"   Dwse diaspora:"<<"\n";  cin>>s;  cerr<<"   Plhthos tyxaiwn arithmwn:"<<"\n";  cin>>j;  cerr<<"\n";     time_t seconds;     time(&seconds);     srand((unsigned int) seconds);  while(i<j){  //tha paraksw tyxaious omoiomorfhs katanomhs sto (m-4s,m+4s)     x=(float)(rand()%(b-a)+a)/1000.0;//x :tyxaio omoiomorfhs katanomhs sto (0,1)    x=(x-0.5)*8*s+m;//to (0,1) metaferetai sto (-0.5,0.5) kai diasteletai kata                     // 8 diaspores ,meta metaferetai gyro apo thn mesh timh m.  //Grafw thn f(x):Gauss synarthsei twn m,s      f=(pow(2.718281828,-(pow((x-m)/s,2))/2)) / (s*(sqrt(2*3.141592654)));  //Zari... y tyxaio omoiomorfhs katanomhs sto (o , f max)    y=(float)(rand()%(b-a)+a)/1000.0;  //y sto (0,1)    y=y/(s*(sqrt(2*3.1415926)));       //y sto (0 , f max)      if(f>=y) {cout<<x<<endl;i++;}  }return 0;}