Results 1 to 4 of 4

Thread: Successive Approximation

  1. #1

    Successive Approximation

    An efficient way of solving difficult equations like a^3+5*a^2=20.

    All you have to do is formulate a null expression: a^3+5*a^2-20 and plug it in.

    [code=thinbasic]


    'SUCCESSIVE APPROXIMATION USING NEGATIVE FEEDBACK

    uses "oxygen"
    '
    '
    dim src as string

    src = "
    dim as double a1,a2,i1,i2,fbr
    dim as long i
    '
    function ff( a as double ) as double
    '
    'NULL EXPRESSIONS
    '
    function=a*a-2 ' square root of 2
    'function=a*a*a-2 ' cube root of 2
    'function=abs (sin(a/6)-0.5) 'pi
    'function=abs((1/a)-a+1) 'phi
    end function

    i=0
    a1=1
    a2=a1+1 ' second extimate of ans
    i1=ff(a1) ' first result
    i2=ff(a2) ' second result
    do
    fbr=(a2-a1)/(i2-i1) : a1=a2 : i1=I2 : a2=a2-fbr*i2 : i2=ff(a2)
    if (abs(a2-a1)<1e-16)or(i>1000) then exit do
    inc i
    loop

    print str(a1) `
    ` str(i) ` iterations`


    terminate

    "

    o2_basic src

    'msgbox 0, o2_len+$cr+o2_prep "o2h "+src

    if len(o2_error) then msgbox 0, o2_error : stop

    o2_exec


    [/code]

  2. #2
    Super Moderator Petr Schreiber's Avatar
    Join Date
    Aug 2005
    Location
    Brno - Czech Republic
    Posts
    7,128
    Rep Power
    732

    Re: Successive Approximation

    Charles,

    thanks for this example, it ringed the nostalgic string in my mind - my RPN based calculator uses very similar concept for SOLVER application.
    Learn 3D graphics with ThinBASIC, learn TBGL!
    Windows 10 64bit - Intel Core i5-3350P @ 3.1GHz - 16 GB RAM - NVIDIA GeForce GTX 1050 Ti 4GB

  3. #3
    thinBasic MVPs danbaron's Avatar
    Join Date
    Jan 2010
    Location
    California
    Posts
    1,378
    Rep Power
    152

    Re: Successive Approximation

    With respect to your original equation, Charles:

    a^3 + 5*a^2 = 20,

    here is one solution (I think the other two are complex).

    -(1/3)*[5 + {[-290 + (21600)^(1/2)]/2}^(1/3) + {[-290 - (21600)^(1/2)]/2}^(1/3)]

    According to my calculator, that is approximately, 1.72457672763.

    Dan
    "You can't cheat an honest man. Never give a sucker an even break, or smarten up a chump." - W.C.Fields

  4. #4

    Re: Successive Approximation


    Yes my program agrees Dan. though it gives an extra 4 digits at the end: 1848.

    It did this in only 7 iterations, which makes the technique tolerable even for relatively simple equations. But I appreciate the satisfaction and insight gained in solving the challenging ones yourself.


Similar Threads

  1. Sierpinski triangle approximation .... using L-System :D
    By Petr Schreiber in forum TBGL General
    Replies: 7
    Last Post: 11-03-2008, 00:08

Members who have read this thread: 0

There are no members to list at the moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •