Created
September 23, 2014 18:30
-
-
Save felipeborges/8ae24ef05c7a76773043 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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