using System;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Markup;
namespace cauchy
{
public partial class cauchyFrom : Form
{
int i, j; double r;
double[] value;
// generate(0,1)interval random number
Random rd = new Random(Guid.NewGuid().GetHashCode());
//double uniform(double double int*)
public cauchyFrom()
{
InitializeComponent();
}
double cauchy(double a,double b)
{ //cauchy distribution, no mean, no sigma,
//but distrubution is continuous function!
r = rd.NextDouble();
r =a-b/Math.Tan(Math.PI*r);
return r;
}
private void btCreateData_Click(object sender, EventArgs e)
{
double[] value = new double[50];
double a=5.0, b=1.0,t;
for (int i = 0; i < value.Length; i++)
{
value[i] = 0.0;
}
tbPointData.Clear();
tbDensityData.Clear();
foreach (var series in chart_PointDistribute.Series)
{
series.Points.Clear();
}
foreach (var series in chart_MakeCurve.Series)
{
series.Points.Clear();
}
for (i = 0; i < 10; i++)
{
for (j = 0; j < 5; j++)
{
r=cauchy(a, b);
value[i * 5 + j] = r;
this.chart_PointDistribute.Series[0].Points.AddXY(i * 5 + j, r);
tbPointData.AppendText((i * 5 + j).ToString() + ": \t" + r.ToString("f6") + "\t\n ");
}
}
//f(x)=β/Π*(β² +(x-a)²)
double[] density = new double[50];
for (int i = -25; i < 25; i ++){
density[i + 25] = b/(Math.PI*(Math.Pow(b,2)+Math.Pow(i-a,2)));
}
for(int i = -25; i < 25; i++) {
this.chart_MakeCurve.Series[0].Points.AddXY(i,density[i+25]);
tbDensityData.AppendText("X is:" + i.ToString("f0")+"\t" + "Density is:"+density[i+25].ToString("f4")+"\t\n");
}
}
}
}
Cauchy Distribution
于 2023-08-02 15:33:57 首次发布