reb
Class REB_Newton

Object
  extended by common:Generic
      extended by common:Formula
          extended by common:ConvergentFormula
              extended by reb:REB_Newton

class 
ConvergentFormula:REB_Newton

Newton with multiple convergence methods.

In addition to the the well-known Newton's method for determining roots of polynomials, three additional methods can be used: Householder's method, Halley's method and Schroder's Method. All three are described in Mathworld. This formula has three additional methods which are hybrid methods.

A modified bailout procedure is used which provide better behavior with complex powers with respect to coloring formulas.


Ultra Fractal Source

Toggle UF Source Code Display

 class REB_Newton(common.ulb:ConvergentFormula) {
 ; Newton with multiple convergence methods. <br>
 ; <p>
 ; In addition to the the well-known Newton's method for determining roots of
 ; polynomials, three additional methods can be used: Householder's method,
 ; Halley's method and Schroder's Method. All three are described in Mathworld.
 ; This formula has three additional methods which are hybrid methods.
 ; <p>
 ; A modified bailout procedure is used which provide better behavior with complex
 ; powers with respect to coloring formulas.
 public:
   import "common.ulb"
 
   ; constructor
   func REB_Newton(Generic pparent)
      ConvergentFormula.ConvergentFormula(pparent)
    endfunc
 
   ; initialize the formula
   complex func Init(complex pz)
     ConvergentFormula.Init(pz)
     fz = 0
     fzp = 0
     fzp2 = 0
     pwrtest = 10^(100/cabs(@p_power))
     bTest = false
     isnear = @p_bailout*cabs(@p2)^cabs(@p_power)
     oldz = 0
     cz = 0
     return pz
   endfunc
 
   ; call for each iterated point
   complex func Iterate(complex pz)
     ConvergentFormula.Iterate(pz)
     oldz = pz
     fz = pz^@p_power - @p2
     fzp = @p_power*pz^(@p_power-1)
     fzp2 = @p_power*(@p_power-1)*pz^(@p_power-2)
     if @converge == 0                          ; Newton
       pz = pz - fz/fzp
     elseif @converge == 1                      ; Householder
       pz = pz - fz/fzp*(1 + fz*fzp2/(2*fzp^2))
     elseif @converge == 2                      ; Halley
       pz = pz - 2*fz*fzp/(2*fzp^2 - fz*fzp2)
     elseif @converge == 3                      ; Schroder
       pz = pz - fz*fzp/(fzp^2 - fz*fzp2)
     elseif @converge == 4                      ; Ho custom
       pz = pz - fz/fzp*(1 + fz*fzp2/(@custom*fzp^2))
     elseif @converge == 5                      ; Ha custom
       pz = pz - 2*fz*fzp/(@custom*fzp^2 - fz*fzp2)
     elseif @converge == 6                      ; H_S custom
       pz = pz - @custom*fz*fzp/(@custom*fzp^2 - fz*fzp2)
     endif
     btest = (|oldz-pz| < isnear)
     cz = |pz|
     return pz
   endfunc
 
   ; Override the default function for bailout
   bool func IsBailedOut(complex pz)
     return  !(!btest && (cz < pwrtest))
   endfunc
   
 protected:  
    complex fz
    complex fzp
    complex fzp2
    float pwrtest
    bool bTest
    float isnear
    complex oldz
    float cz
 
 default:
   title = "Newton"
   int param v_newton
     caption = "Version (Newton)"
     default = 100
     hint = "This version parameter is used to detect when a change has been made to the formula that is incompatible with the previous version. When that happens, this field will reflect the old version number to alert you to the fact that an alternate rendering is being used."
     visible = @v_newton < 100
   endparam
   heading
     text = "This a Newton with multiple convergence options."
   endheading
   param p_power
     caption = "Power"
     default = (3,0)
   endparam
   param p2
     caption = "Root"
     default = (1,0)
   endparam
   param p_bailout
     caption = "Bailout value"
     default = 1e-12
     max = 0.1
   endparam
   heading
     caption = "Convergence Methods"
   endheading
   param converge
     caption = "Convergence Method"
     default = 0
     enum = "Newton" "Householder" "Halley" "Schroder" "Ho Custom" \
            "Ha Custom" "H_S Custom"
   endparam
   float param custom
     caption = "H_S Constant"
     default = 1.5
     visible = @converge==4 || @converge==5  || @converge==6
   endparam
 }
 


Constructor Summary
REB_Newton()
           
REB_Newton(Generic pparent)
          constructor
 
Method Summary
 complex Init(complex pz)
          initialize the formula
 boolean IsBailedOut(complex pz)
          Override the default function for bailout
 complex Iterate(complex pz)
          call for each iterated point
 
Methods inherited from class common:ConvergentFormula
GetLowerBailout
 
Methods inherited from class common:Formula
GetPrimaryExponent, GetUpperBailout
 
Methods inherited from class common:Generic
GetParent
 
Methods inherited from class Object
 

Constructor Detail

REB_Newton

public REB_Newton(Generic pparent)
constructor


REB_Newton

public REB_Newton()
Method Detail

Init

public complex Init(complex pz)
initialize the formula

Overrides:
Init in class ConvergentFormula
Parameters:
pz - seed value for the sequence; for a normal fractal formula, this will be #pixel
Returns:
first value in the sequence; this corresponds to #z in a fractal formula

Iterate

public complex Iterate(complex pz)
call for each iterated point

Overrides:
Iterate in class ConvergentFormula
Parameters:
pz - previous value in the sequence; corresponds to #z in a fractal formula. Note that you should always use this value for computing the next iteration, rather than a saved value, as the calling code may modify the returned value before passing it back to the next Iterate() call.
Returns:
the next value in the sequence

IsBailedOut

public boolean IsBailedOut(complex pz)
Override the default function for bailout

Overrides:
IsBailedOut in class ConvergentFormula
Parameters:
pz - last sequence value to test; this should be the value returned from the previous Iterate() call. Note that it is acceptable to ignore pz and use m_BailedOut, but any code calling IsBailedOut() should pass in the correct pz for Formula classes which do not use m_BailedOut.
Returns:
true if the sequence has bailed out (i.e. should be terminated)