this.tChart1.Axes.DepthTop.Automatic = true;
this.tChart1.Axes.DepthTop.Grid.ZPosition = 0;
this.tChart1.Axes.DepthTop.Labels.Font.Shadow.Visible = false;
this.tChart1.Axes.DepthTop.Labels.Shadow.Visible = false;
this.tChart1.Axes.DepthTop.Title.Font.Shadow.Visible = false;
this.tChart1.Axes.DepthTop.Title.Shadow.Visible = false;
this.tChart1.Axes.Left.Automatic = true;
this.tChart1.Axes.Left.Grid.ZPosition = 0;
this.tChart1.Axes.Left.Labels.Font.Shadow.Visible = false;
this.tChart1.Axes.Left.Labels.Shadow.Visible = false;
this.tChart1.Axes.Left.Title.Font.Shadow.Visible = false;
this.tChart1.Axes.Left.Title.Shadow.Visible = false;
this.tChart1.Axes.Right.Automatic = true;
this.tChart1.Axes.Right.Grid.ZPosition = 0;
this.tChart1.Axes.Right.Labels.Font.Shadow.Visible = false;
this.tChart1.Axes.Right.Labels.Shadow.Visible = false;
this.tChart1.Axes.Right.Title.Font.Shadow.Visible = false;
this.tChart1.Axes.Right.Title.Shadow.Visible = false;
this.tChart1.Axes.Top.Automatic = true;
this.tChart1.Axes.Top.Grid.ZPosition = 0;
this.tChart1.Axes.Top.Labels.Font.Shadow.Visible = false;
this.tChart1.Axes.Top.Labels.Shadow.Visible = false;
this.tChart1.Axes.Top.Title.Font.Shadow.Visible = false;
this.tChart1.Axes.Top.Title.Shadow.Visible = false;
this.tChart1.Cursor = System.Windows.Forms.Cursors.Default;
this.tChart1.Footer.Font.Shadow.Visible = false;
this.tChart1.Footer.Shadow.Visible = false;
//
this.tChart1.Header.Font.Shadow.Visible = false;
this.tChart1.Header.Lines = new string[] {
""};
this.tChart1.Header.Shadow.Visible = false;
this.tChart1.Legend.Font.Shadow.Visible = false;
this.tChart1.Legend.Title.Font.Bold = true;
this.tChart1.Legend.Title.Font.Shadow.Visible = false;
this.tChart1.Legend.Title.Pen.Visible = false;
this.tChart1.Legend.Title.Shadow.Visible = false;
this.tChart1.Location = new System.Drawing.Point(567, 15);
this.tChart1.Name = "tChart1";
this.tChart1.Panel.Bevel.Outer = Steema.TeeChart.Drawing.BevelStyles.None;
this.tChart1.Panel.ImageBevel.Width = 1;
this.tChart1.Panel.Shadow.Visible = false;
this.tChart1.Series.Add(this.points1);
this.tChart1.Series.Add(this.fastLine2);
this.tChart1.Size = new System.Drawing.Size(483, 230);
this.tChart1.SubFooter.Font.Shadow.Visible = false;
this.tChart1.SubFooter.Shadow.Visible = false;
this.tChart1.SubHeader.Font.Shadow.Visible = false;
this.tChart1.SubHeader.Shadow.Visible = false;
this.tChart1.TabIndex = 0;
this.tChart1.Walls.Back.AutoHide = false;
this.tChart1.Walls.Back.Shadow.Visible = false;
this.tChart1.Walls.Bottom.AutoHide = false;
this.tChart1.Walls.Bottom.Shadow.Visible = false;
this.tChart1.Walls.Left.AutoHide = false;
this.tChart1.Walls.Left.Shadow.Visible = false;
this.tChart1.Walls.Right.AutoHide = false;
this.tChart1.Walls.Right.Shadow.Visible = false;
//
// label5
//
this.label5.AutoSize = true;
this.label5.Location = new System.Drawing.Point(-1, 2);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(61, 13);
this.label5.TabIndex = 8;
this.label5.Text = "Матриця Х";
//
// label6
//
this.label6.AutoSize = true;
this.label6.Location = new System.Drawing.Point(-1, 249);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(61, 13);
this.label6.TabIndex = 9;
this.label6.Text = "Матриця S";
//
// pictureBox1
//
this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
this.pictureBox1.Location = new System.Drawing.Point(817, 116);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(196, 56);
this.pictureBox1.TabIndex = 10;
this.pictureBox1.TabStop = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(1062, 566);
this.Controls.Add(this.pictureBox1);
this.Controls.Add(this.label6);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.tChart1);
this.Controls.Add(this.dataGrid2);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.panel1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Критерiй Байєcа – Лаплаcа (матриця фoрмуєтьcя за екcпoненцiальним закoнoм). Курcoва" +
" рoбoта cтудента групи ПЗc-07-1 Кoчеткoва O.М.";
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
this.panel1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.numericUpDown4)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown3)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.dataGrid2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
bl.lambda = Convert.ToDouble(numericUpDown1.Value);
//bl.delta = Convert.ToDouble(numericUpDown2.Value);
bl.I = Convert.ToInt32(numericUpDown3.Value);
bl.J = Convert.ToInt32(numericUpDown4.Value);
bl.Fill();
//MessageBox.Show("swsds");
bl.Find_v();
bl.Find_max_v();
textBox1.Text = bl.calc;
tChart1.Series[0].Clear();
tChart1.Series[1].Clear();
for (int i = 0; i < bl.I; i++)
{
for (int j = 0; j < bl.J; j++)
{
tChart1.Series[0].Add(bl.x[i,j], bl.y[i,j]);
tChart1.Series[1].Add(bl.x[i,j], bl.Find_F(bl.x[i,j]));
}
textBox1.Text += "\r\n";
}
DataTable dt = new DataTable("X_S");
DataSet ds = new DataSet("X");
DataTable dt1 = new DataTable("S");
for (int i = 1; i <= bl.J; i++)
{
dt.Columns.Add(i.ToString());
dt1.Columns.Add(i.ToString());
}
string[] s = new string[bl.J];
string[] s1 = new string[bl.J];
for (int i = 0; i < bl.I; i++)
{
for (int j = 0; j < bl.J; j++)
{
s[j] = String.Format(bl.format,bl.x[i,j]);
s1[j] = String.Format(bl.format,bl.y[i,j]);
}
dt.Rows.Add(s);
dt1.Rows.Add(s1);
}
ds.Tables.Add(dt);
dataGrid1.DataSource = ds.Tables[0];
dataGrid1.Expand(-1);
dataGrid1.SelectionBackColor = Color.SeaShell;
dataGrid1.SelectionBackColor = Color.Green;
dataGrid1.Select(bl.max_v[0]);
ds.Tables.Add(dt1);
dataGrid2.DataSource = ds.Tables[1];
dataGrid2.Expand(-1);
dataGrid2.SelectionBackColor = Color.SeaShell;
dataGrid2.SelectionBackColor = Color.Green;
dataGrid2.Select(bl.max_v[0]);
}
private void numericUpDown1_ValueChanged(object sender, System.EventArgs e)
{
bl.lambda = Convert.ToDouble(numericUpDown1.Value);
}
private void numericUpDown2_ValueChanged(object sender, System.EventArgs e)
{
bl.delta = Convert.ToDouble(numericUpDown2.Value);
}
private void numericUpDown3_ValueChanged(object sender, System.EventArgs e)
{
bl.I = Convert.ToInt32(numericUpDown3.Value);
}
private void numericUpDown4_ValueChanged(object sender, System.EventArgs e)
{
bl.J = Convert.ToInt32(numericUpDown4.Value);
}
}
}
Клаc CL_Simple_BL.cs:
using System;
using System.Windows.Forms;
namespace BL
{
/// <summary>
/// Summary description for CL_Simple_BL.
/// </summary>
public class CL_Simple_BL
{
public const int N = 100;
public int I;
public int J;
public double[,] x = new double[N,N];
public double[,] y = new double[N,N];
public double[] v = new double[N];
public int[] max_v = new int[N];
public string calc;
public string format;
public int c;
public double lambda;
public double delta;
double d;
//double a;
double S;
double X;
double P;
double F;
Random r;
public CL_Simple_BL()
{
c = 0;
I = J = 10;
lambda = 1.0;
delta = 0.001;
r = new Random(DateTime.Now.Millisecond);
format = "{0:F2}";
}
/*public double Find_a()
{
a = - (1/(2*Math.Pow(lambda,2)));
return a;
}*/
public double Find_d()
{
d = 1 - S + delta;
return d;
}
// мах х oт oбратнoй функции
public double Find_X()
{
//X = Math.Sqrt(Math.Log(d)/a);
X = (Math.Log(delta))/(-lambda);
return X;
}
//
public double Find_P(double dx)
{
//P = 1 - Math.Exp(-0.5*Math.Pow(dx/lambda, 2));
P = 1 - Math.Pow(Math.E, (-lambda*dx));
return P;
}
public double Find_F(double dx)
{
//F = (dx*Math.Exp((-2*Math.Pow(dx,2))/(2*Math.Pow(lambda, 2))))/Math.Pow(lambda, 2);
F = lambda*(Math.Pow(Math.E,(-lambda*dx)));
return F;
}
public void Find_v()
{
calc = "";
for (int i = 0; i < I; i++)
{
v[i] = 0;
calc += "v(x"+(i+1).ToString()+") = ";
for (int j = 0; j < J; j++)
{
v[i] += (x[i, j]*y[i, j]);
calc += String.Format(format,x[i, j]) + " * " + String.Format(format,y[i, j]);
if (j < J-1)
{
calc += " + ";
}
}
calc += " = " + String.Format(format,v[i]) + ";\r\n";
}
}
public void Find_max_v()
{
c = 0;
string s = "";
double max = 0;
for (int i = 0; i < I; i++)
{
if (v[i]>=max)
{
max = v[i];
}
}
calc += "\r\nXopt є {";
s += "Xopt є {";
for (int i = 0; i < I; i++)
{
if(v[i] == max)
{
if (c > 0)
{
calc += ", ";
}
max_v[c] = i;
calc += "x" + (i + 1).ToString();
s += "x" + (i + 1).ToString();
c++;
}
}
calc += "};";
s += "};";
MessageBox.Show(s, "Результат");
}
public void Init()
{
S = 1.0;
//Find_a();
Find_d();
Find_X();
}
public void Fill()
{
double t = 0, q = 0;
for (int i = 0; i < I; i++)
{
Init();
int j = 0;
while (j < J-1)
{
Find_d();
Find_X();
if (j == J-1)
{
t = 1;
}
else
{
t = r.NextDouble();
}
t = X*t;
q = Find_P(t);
if (S - q >= 0)
{
S = S - q;
x[i, j] = t;
y[i, j] = q;
j++;
}
}
}
}
}
}