We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent db41024 commit 22f84aeCopy full SHA for 22f84ae
math/bisection.lua
@@ -0,0 +1,30 @@
1
+--[[
2
+ Lua implementation of bissetion method
3
+
4
+ Author: Micael Machado Gomes (micaellgoms@gmail.com)
5
+--]]
6
7
+function f(x)
8
+ local y = 2*x - math.sin(x) - 4
9
+ return y
10
+end
11
12
+-- defined random range
13
+a, b = 2, 3
14
+-- defined error to stop loop
15
+erro = 0.001
16
+-- defined Xn; slipt range;
17
+x = (a + b)/2
18
19
+k = 1
20
+while math.abs(f(x)) >= erro and math.abs(b-a) >= erro do
21
+ if f(a)*f(x) < 0 then
22
+ b = x
23
+ else
24
+ a = x
25
+ end
26
27
+ -- update Xn
28
+ x = (a + b)/2
29
+ k = k + 1
30
0 commit comments