summaryrefslogtreecommitdiff
path: root/test/bisect.lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/bisect.lua')
-rw-r--r--test/bisect.lua6
1 files changed, 3 insertions, 3 deletions
diff --git a/test/bisect.lua b/test/bisect.lua
index 8b720654..4de9e99b 100644
--- a/test/bisect.lua
+++ b/test/bisect.lua
@@ -1,9 +1,9 @@
-$debug
-- bisection method for solving non-linear equations
function bisect(f,a,b,fa,fb)
write(n," a=",a," fa=",fa," b=",b," fb=",fb,"\n")
local c=(a+b)/2
+ if c==a or c==b then return c end
if abs(a-b)<delta then return c end
n=n+1
local fc=f(c)
@@ -12,10 +12,10 @@ end
-- find root of f in the inverval [a,b]. bisection needs that f(a)*f(b)<0
function solve(f,a,b)
- delta=1e-6 -- tolerance
+ delta=1e-9 -- tolerance
n=0
local z=bisect(f,a,b,f(a),f(b))
- write(format("after %d steps, root is %.10g\n",n,z))
+ write(format("after %d steps, root is %.10g, f=%g\n",n,z,f(z)))
end
-- our function