Skip to content

Commit 0fba7a9

Browse files
Merge pull request #11 from ashishworkspace/feature/bisection
Bisection in Python
2 parents 8b27ff0 + 45d2f48 commit 0fba7a9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

Random Python Programs/bisection.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
def equation(x):
2+
return (x**3 - 4*x - 9)
3+
4+
a = float(input("Enter the inital range value: "))
5+
b = float(input("Enter the final range value: "))
6+
7+
iteration = int(input("Enter the number of Iteration: "))
8+
9+
if(equation(a)*equation(b) > 0):
10+
print("Wrong Input! Root does not exits")
11+
else:
12+
while(iteration != 0):
13+
x = (a+b)/2
14+
if(equation(x)<0):
15+
a = x
16+
elif(equation(x)>0):
17+
b = x
18+
else:
19+
print("Root is Zero")
20+
print("Root : "+str(x))
21+
iteration -= 1

0 commit comments

Comments
 (0)