Skip to content

Commit

Permalink
Update fp.py
Browse files Browse the repository at this point in the history
  • Loading branch information
afrizaloky committed May 4, 2019
1 parent 707d011 commit 1480bdc
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions fp.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,23 @@
import sys
from prettytable import PrettyTable




#Value from function
def f(value):

res = expr.subs(x, value)
return res


#False Position Method
def false_position(xu, xl):
atas = xu*f(xl)-xl*f(xu)
bawah = f(xl)-f(xu)
xm = atas/bawah
return xm

#Input
x = var('x')

Expand All @@ -30,7 +47,7 @@


try:
RAE = float(input("Enter the value of tollerance (0.0001) = "))
RAE = float(input("Enter the value of Aproximation Error (0.0001) = "))
except:
print("input yang anda masukkan tidak sesuai")
sys.exit()
Expand All @@ -39,24 +56,13 @@
counter = 0
x_old = 0

#Value from function
def f(value):

res = expr.subs(x, value)
return res


#False Position Method
def false_position(xu, xl):
atas = xu*f(xl)-xl*f(xu)
bawah = f(xl)-f(xu)
xm = atas/bawah
return xm

#Definition Table
t = PrettyTable()
t.field_names=["i", "xi", "Tollerance"]
t.field_names=["i", "xi", "Aproximation Error"]


try:
#looping
while RAE<RAE_now:


Expand All @@ -68,11 +74,9 @@ def false_position(xu, xl):
xl=xm
elif(diff==0):
print("True Value = "+str(xm)+".")
break
sys.exit()
else:
print("Program Error")
break
sys.exit()
if(counter==0):
x_new = xm
Expand All @@ -89,4 +93,6 @@ def false_position(xu, xl):
except:
print("Program Error")
sys.exit()


print(t)

0 comments on commit 1480bdc

Please sign in to comment.