Charles,
thanks for this example, it ringed the nostalgic string in my mind - my RPN based calculator uses very similar concept for SOLVER application.
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]
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
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
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.
Bookmarks