ax^2 + bx + c = 0
の実係数a,b,cを乱数(-2,147,483,648 ~ 2,147,483,647)で発生させ
実数解と虚数解の割合を計算しました。
10,000,000回計算した結果
実数解:6272888(62.72888%)
虚数解:3727112(37.27112%)
二重解:0(0%)
なぜ、この割合なのかを数学的に証明できたらと思っています。
以下にソースコードの一部を掲載します。
private void abc_r_2()
{
decimal a;
decimal b;
decimal c;
decimal d;
byte[] bs = new byte[4];
RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
int m = 0; //重解 multiple root
int r = 0;
int i = 0;
decimal total = 10000000;
int n = 1;
for (int x = 0; x < total; x++)
{
do
{
rng.GetBytes(bs);
//Int32に変換する
a = BitConverter.ToInt32(bs, 0);
//a = -1;
} while (a == 0);
rng.GetBytes(bs);
//Int32に変換する
b = BitConverter.ToInt32(bs, 0);
rng.GetBytes(bs);
//Int32に変換する
c = BitConverter.ToInt32(bs, 0);
d = b * b - 4 * a * c;
if (d == 0)
{
m++;
}
else if (d > 0)
{
r++;
}
else
{
i++;
}
}
decimal m_p = m * 100 / total;
decimal r_p = r * 100 / total;
decimal i_p = i * 100 / total;
Invoke(new dldl(delegate
{
textBox1.AppendText("実数解:" + r.ToString() + "(" + r_p.ToString() + "%)" +
"虚数解:" + i.ToString() + "(" + i_p.ToString() + "%)" +
"二重解:" + m.ToString() + "(" + m_p.ToString() + "%)" + Environment.NewLine);
button1.Enabled = true;
}));
}