Skip to content

Instantly share code, notes, and snippets.

@felipeborges
Created September 23, 2014 18:30
Show Gist options
  • Save felipeborges/8ae24ef05c7a76773043 to your computer and use it in GitHub Desktop.
Save felipeborges/8ae24ef05c7a76773043 to your computer and use it in GitHub Desktop.
import math
pi = math.pi
cos = math.cos
def f(x):
return cos(pi*(x+1)/8.0) + (0.148*(x)) -0.9062
def mod(x):
if x > 0:
return x
else:
return (-1*x)
def x(a,b):
return ((a*mod(f(b))) + (b*mod(f(a))))/(mod(f(a)) + mod(f(b)))
y = 1
b = 0
k = 1
while y > 10**(-3):
b = x(-1, b)
y = f(b)
print ("x%d = %f f(x%d) = %f" % (k, b, k, y))
k+=1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment