Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleUse Newton's method on the equation Z^3 - 3^Z to draw fractals in Visual Basic 6
DescriptionThis example shows how to use Newton's method on the equation Z^3 - 3^Z to draw fractals in Visual Basic 6.
KeywordsNewton's method, non-polynomial function, root, function, fractal
CategoriesAlgorithms, Graphics
 
This example is exactly like Use Newton's method on the equation Z^2 - 2^Z to draw fractals in Visual Basic 6 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
Dim x3 As Complex
Dim three As Complex
Dim three_tothe_x As Complex

    ' x^3.
    Set x3 = x.Times(x).Times(x)

    ' 3 + 0i.
    Set three = NewComplex(3, 0)

    ' 3^x.
    Set three_tothe_x = three.ToThePowerOf(x)

    ' x^3 - 3^x.
    Set F = 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
Dim three As Complex
Dim three_times_x2 As Complex
Dim three_tothe_x As Complex
Dim three_tothe_x_log3 As Complex
Dim x2 As Complex

    ' 3.
    Set three = NewComplex(3, 0)

    ' x^2.
    Set x2 = x.Times(x)

    ' 3 * x^2.
    Set three_times_x2 = three.Times(x2)

    ' 3^x.
    Set three_tothe_x = three.ToThePowerOf(x)

    ' 3^x * ln(2).
    Set three_tothe_x_log3 = _
        three_tothe_x.TimesComponents(Log(3), 0)

    ' 3 * x^2 - 3^x * ln(3).
    Set dFdx = three_times_x2.Minus(three_tothe_x_log3)
End Function
 
See the code for additional details.

Unfortunately this code is quite slow because of all of the heavy-lifting it does manipulating Complex objects. The VB .NET version is much faster.

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

 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated