Goal amount for this month: 100 USD, Received: 0 USD (0%)
Donate to support this site and ThinBASIC project development

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. ## 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.

3. ## 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

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.

#### Posting Permissions

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