Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
new_zap_do_3.2.docx
Скачиваний:
1
Добавлен:
01.03.2025
Размер:
975.33 Кб
Скачать
      1. МодульExponent

Данный модуль осуществляет расчет основных характеристик экспоненциального распределения.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using ZedGraph;

namespace Kyrsovoi_erm

{

class Exponent

{

private PointPairList flist = new PointPairList();

private PointPairList glist;

private Double alpha=1;

// private Double discret= 0.001;

//private Double ymin = 0;

// private Double ymax = 1;

private Double xmin;

private Double xmax;

private Double[] process;

// private Double[] process_sort;

Double korigor;

Double[] gistX;

int c_count;

public void Set_alpha(Double a)

{

alpha = a;

}

public Double getxmin()

{

return xmin;

}

public Double getxmax()

{

return xmax;

}

public void Analise_process(Double [] p)

{

process = new Double[p.Length];

xmax = process[0];

xmin = process[0];

process = p;

size = p.Length;

// c_count = c;

for (int i = 0; i < process.Length; i++)

{

if (process[i] < xmin)

{

xmin = process[i];

}

if (process[i] > xmax)

{

xmax = process[i];

}

}

}

private int size = 0;

public int getflistCount()

{

return flist.Count();

}

public bool glistIsEmpty()

{

if (glist == null)

return true;

return false;

}

public Double[] getProcess()

{

return process;

}

/* public Double getDiscret()

{

return discret;

}*/

public bool flistIsEmpty()

{

if (flist.Count == 0)

return true;

return false;

}

public PointPairList getGlist()

{

return glist;

}

public PointPairList getFlist()

{

return flist;

}

public void update(Double a, int s)

{

alpha = a;

//discret = d;

size = s;

}

public PointPairList Calculate_Exponenta_func(Double a, int s)

{

process = new Double[s];

//process_sort = new Double[s];

Random r = new Random();

double y;

double x_res;

update(a, s);

flist.Clear();

y = r.NextDouble();

x_res = f_exp_r(a, y);

process[0] = x_res;

xmax = x_res;

xmin = x_res;

flist.Add(x_res, y);

for ( int i =1 ; i < size; i ++)

{

y = r.NextDouble();

x_res=f_exp_r(a,y);

// добавим в список точку

flist.Add(x_res,y);

process[i] = x_res;

if (x_res > xmax)

{

xmax = x_res;

// ymax2 = y;

}

if (x_res < xmin)

{

xmin = x_res;

// ymax2 = y;

}

}

flist.Sort();

/* for (int i = 0; i < size; i++)

{

process_sort[i] = flist.ElementAt(i).X;

}*/

return flist;

}

public PointPairList Calculate_Exponenta_func_from_file()

{

//process_sort = new Double[size];

double x;

double y_res;

flist.Clear();

for (int i = 0; i < size; i++)

{

x = process[i];

y_res = f_exp(x);

flist.Add(x, y_res);

}

flist.Sort();

/* for (int i = 0; i < size; i++)

{

process_sort[i] = flist.ElementAt(i).X;

}*/

return flist;

}

private double f_exp(Double x)

{

if (x == 0)

{

return 0;

}

return 1-(Math.Exp(-alpha*x));

}

private double f_exp_r(Double a, Double y)

{

if (y == 0)

{

return 0;

}

return (-1 / a) * (Math.Log((1 - y), Math.E));

}

private double f_exp_densitY(double x)

{

if (x < 0)

{

return 0;

}

else

{

return alpha*Math.Pow(Math.E,(-alpha*x));

}

}

public PointPairList Calculate_theoretical_density()

{

PointPairList list = new PointPairList();

Double y ;

Double x;

Double sum = 0;

for(int i=0;i<c_count;i++)

{

x =gistX[i];

y = f_exp_densitY(x);

sum += y;

//list.Add(x,y);

}

for (int i = 0; i < c_count; i++)

{

x = gistX[i];

y = f_exp_densitY(x);

list.Add(x,y/sum);

}

return list;

}

public PointPairList Calculate_gist(int c_c)

{

c_count = c_c;

Double [] gistY = new Double[c_c];

gistX = new Double[c_c];

korigor = (xmax - xmin) / c_c; //ширина коридора

//Считаем середину для каждого столбика гистограммы

int h = 0;

for (Double i = xmin+korigor/2; i < xmax; i +=korigor)

{

gistX[h] = i;

h++;

}

int j;

for (int i = 0; i < size; i++)

{

j = (int) (((process[i])-xmin) / korigor);

if ((((process[i]) - xmin) % korigor != 0) && ((process[i]) != xmax))

{

gistY[j] = gistY[j] + 1;

}

else

{

if (((process[i]) != xmax) && ((process[i]) != xmin))

{

gistY[j - 1] = gistY[j - 1] + 1/2;

gistY[j] = gistY[j] + 1/2;

}

else

{

if ((process[i]) == xmax)

gistY[j - 1] = gistY[j - 1] + 1;

if ((process[i]) == xmin)

gistY[j] = gistY[j] + 1;

}

}

}

Double temp=0;

for (int i = 0; i < c_c; i++)

{

gistY[i] = gistY[i] / size;

temp += gistY[i];

}

temp = temp * korigor;

glist = new PointPairList(gistX, gistY);

return glist;

}

}

}

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]