# Use Newton’s method to draw fractals for polynomial equations in C# This example uses Newton’s method to draw a fractal for the polynomial equation F(z) = zN + zN-1 + … + z + 1.

Once you know how to use Newton’s methods to generate one kind of fractal, it’s easy to make new ones. Simply use the examples in the links above and change the equation and its derivative. This example is the same as the previous one except it uses the equation:

`F(z) = zN + zN-1 + ... + z + 1`

Fortunately it’s easy to take the derivative of this equation:

`dFdz(z) = N * zN-1 + (N - 1) * zN-2 + ... + 2 * z + 1`

The following code shows how the program calculate F(z) and dFdz(z).

```// F(x) = x ^ Power +
//        x ^ (Power - 1) +
//        x ^ (Power - 2) + ... + x + 1
private Complex F(Complex x)
{
Complex result = 1;
for (int i = 1; i <= Power; i++)
{
result += x ^ i;
}
return result;
}

// dFdx(x) = Power * x ^ (Power - 1) +
//     (Power - 1) * x ^ (Power - 2) +
//     (Power - 2) * x ^ (Power - 3) + ... + 1
private Complex dFdx(Complex x)
{
Complex result = 1;
for (int i = 2; i <= Power; i++)
{
result += i * (x ^ (i - 1));
}
return result;
}```

See the code and the previous examples for details.    This entry was posted in algorithms, fractals, graphics, mathematics and tagged , , , , , , , , , , . Bookmark the permalink.

This site uses Akismet to reduce spam. Learn how your comment data is processed.