diff options
| author | Lua Team <team@lua.org> | 1998-07-11 12:00:00 +0000 |
|---|---|---|
| committer | repogen <> | 1998-07-11 12:00:00 +0000 |
| commit | 377347776f1f3d820f92151f70bec667f96d5e6b (patch) | |
| tree | cdb3ba26158df33547dfe765547177afcee119d1 /test/bisect.lua | |
| parent | 4f8c5d0f284e1f4da717aea5008915f185cd2e05 (diff) | |
| download | lua-github-3.1.tar.gz | |
Lua 3.13.1
Diffstat (limited to 'test/bisect.lua')
| -rw-r--r-- | test/bisect.lua | 6 |
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 |
