A new static method, BirgeVieta is added to the Nonlinear system class (class code not shown):
public static double[] BirgeVieta(double[] a, double x0, int nOrder, int nRoots,
int nIterations, double tolerance)r />
{
double x = x0;
double[] roots = new double[nRoots];
double[] a1 = new double[nOrder + 1];
double[] a2 = new double[nOrder + 1];
double[] a3 = new double[nOrder + 1];
for (int j = 0; j <= nOrder; j++)
a1[j] = a[j];
double delta = 10 * tolerance;
int i = 1, n = nOrder + 1, nroot = 0;
while (i++ < nIterations && n > 1)
{
double x1 = x;
a2[n-1] = a1[n-1];
a3[n-1] = a1[n-1];
for (int j = n - 2; j > 0; j--)
{
a2[j] = a1[j] + x1 * a2[j + 1];
a3[j] = a2[j] + x1 * a3[j + 1];
}
a2[0] = a1[0] + x1 * a2[1];
delta = a2[0] / a3[1];
x -= delta;
if (Math.Abs(delta) < tolerance)
{
i = 1;
n--;
roots[nroot] = x;
nroot++;
for (int j = 0; j < n; j++)
{
a1[j] = a2[j + 1];
if (n == 2)
{
n--;
roots[nroot] = -a1[0];
nroot++;
}
}
}
}
return roots;
}
This method takes coefficients of the polynomial as input:
double [ ] a = double[n + 1] {a0, a1, a2, ... an}
|
To use this method, one can also specify an initial guess x0, order of the polynomial, number of roots,
maximum number of iterations, and tolerance.
Testing the Birge Vieta Method
Now, one can examine the BirgeVieta method by using it to solve nonlinear equations. To solve the following nonlinear
equation:
The initial values were set to x0 = 0.0, order of the polynomial = 3, number of roots = 3, tolerance = 0.0001, and
the maximum number of iterations = 1000.
In order to test the nonlinear function defined above, a new method TestBirgeVieta() has been added and executed:
►
|
static void TestBirgeVieta()
{
double[ ] x = NonlinearSystem.BirgeVieta(new double[4]
{ 1, -3, 0, 1.0 }, 0.0, 3, 3, 1000, 0.0001);
listBox1.Items.Add("root 1 = " +(x[0].ToString());
listBox2.Items.Add("root 2 = " +(x[1].ToString());
listBox3.Items.Add("root 3 = " +(x[2].ToString());
this.Text = "Birge Vieta Method / KeystoneMiningPost";
}
|
Results are shown in screen above.
|