Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Stohastic / Stohastic / random / Новый текстовый документ

.txt
Скачиваний:
7
Добавлен:
18.08.2019
Размер:
1.79 Кб
Скачать
#include <stdio.h>
#include <stdlib.h>
#define N 1000
#define s 2
float matozhid(float *x)
{

    float M[N],MM=0;

for(int j=0;j<N;j++)
{
 M[j]=x[j]*1;
 MM+=M[j];
}
return MM/N;
}

float center(float *x,float m)
{

    float M[N],Ms=0;

for(int j=0;j<N;j++)
{
 M[j]=pow(x[j]-m,s);
 Ms+=M[j];
}
return Ms/N;
}

void hist(float *x,float x0,float xn, int n,float *p,int m)
{

   int i,j;
   float xi,dx,pn;
   dx=(xn-x0)/m;
   pn=1.0/n;
   for(int i=0;i<m;i++)
   {
     p[i]=0;
     for(int j=0;j<n;j++)
     {
         xi=x0+i*dx;
         if((xi<x[j])&&(x[j]<xi+dx))
            {
            p[i]+=pn;
            //printf("/////////%d %f \n",j, pn);
            }


     }
   }
}

int X=200;
int myrand()
{
int m=0x7F;
int a=214013,c=2531011;
    X = (a*X+c)%m;
return X;
}

int repeatsearcher(int *x)
{
 int evr=0,c,box[N];
for(int j=1;j<N;j++)
    {


    if(x[j]==x[0])
        {
         evr=j;c=0;
         for(int k=j+1;k<N;k++)
            if(x[k]==x[k-j]) c++;
                else break;
             //printf("cyyyyycle %d\n",c);
        if(c==N-1-j)break;

        }
    }
return evr;
}


int main()
{

    void srand(unsigned seed);
  int rand (void);
//int i;
int Myxa[N];
float x[N],P[100];

FILE *fp = fopen("test.txt","w");
FILE *fp1= fopen("gyst.dat","w");

for(int j=0;j<N;j++)
    {
     x[j]=rand()/(RAND_MAX+1.);
     Myxa[j]=myrand();
    printf("%d\n",Myxa[j]);
    fprintf(fp,"%d %f \n",j, x[j]);

    }
printf(" ME %f\n",matozhid(x));
printf(" Ms %f\n",center(x,matozhid(x)));
hist(x,0,1,N,P,100);

for(int j=0;j<100;j++)
fprintf(fp1,"%d %f \n", j,P[j]);

printf("cycle = %d\n",repeatsearcher(Myxa));

 fclose(fp);
 fclose(fp1);
    return 0;
}
Соседние файлы в папке random