Home Search   What's New Index Books Links Q & A Newsletter Banners   Feedback Tip Jar MSDN Visual Basic Community

Title Use Newton's method on the equation Z^3 - 3^Z to draw fractals in Visual Basic .NET This example shows how to use Newton's method on the equation Z^3 - 3^Z to draw fractals in Visual Basic .NET. Newton's method, non-polynomial function, root, function, fractal, VB .NET Algorithms, Graphics

This example is exactly like Use Newton's method on the equation Z^2 - 2^Z to draw fractals in Visual Basic .NET except it uses a different equation and derivative. The following code shows how the program calculates the function Z^3 - 3^Z and its derivative 3 * Z - 3^Z * ln(3).

```' The function.
' F(x) = x^3 - 3^x.
Private Function F(ByVal x As Complex) As Complex
' x^3
Dim x3 As Complex = x.Times(x).Times(x)

' 3 + 0i
Dim three As New Complex(3, 0)

' 3^x
Dim three_tothe_x As Complex = three.ToThePowerOf(x)

' x^3 - 3^x.
Return x3.Minus(three_tothe_x)
End Function

' The function's derivative.
' dFdx(x) = 3 * x^2 - 3^x * ln(3).
Private Function dFdx(ByVal x As Complex) As Complex
' 3.
Dim three As New Complex(3, 0)

' x^2.
Dim x2 As Complex = x.Times(x)

' 3 * x^2.
Dim three_times_x2 As Complex = three.Times(x2)

' 3^x.
Dim three_tothe_x As Complex = three.ToThePowerOf(x)

' 3^x * ln(3).
Dim three_tothe_x_log3 As Complex = _
three_tothe_x.Times(Log(3), 0)

' 3 * x^2 - 3^x * ln(3).
Return three_times_x2.Minus(three_tothe_x_log3)
End Function```

See the code for additional details.

For more information on Newton's method, see Eric W. Weisstein's article Newton's Method from MathWorld--A Wolfram Web Resource.