Skip to content

Instantly share code, notes, and snippets.

View 19007361's full-sized avatar
🏠
Working from home

CJ Meyer 19007361

🏠
Working from home
  • Stellenbosch, South Africa
View GitHub Profile
def secant(f, a, b, tol=1e-9, n=100):
fmt = "{:2} {:>13.10f} {:>13.10f} {:>13.10f}"
p1, p2 = float(a), float(b)
i = 1
print fmt.format(1, p1, p2, f(p2))
while abs(p1 - p2) > tol and i <= n:
p1, p2 = p2, p2 - (f(p2) * (p2 - p1)) / (f(p2) - f(p1))
i += 1
print fmt.format(i, p1, p2, f(p2))
return p2
def secant(p, pOld, tol, iters):
iters -= 1
pOld = p
pNew = p - (f(p))*(p - pOld)
if abs(pNew - p) < tol or iters == 0:
return pNew
else:
secant(pNew, pOld, tol)
def f(x):
def main():
current_msg_id = ""
ro_uuid_list = []
ro_count = 0
current_song_id = None
while True:
song_id, song_artist, song_name = get_song()
if song_id is None and song_artist is None and song_name is None:
song_id = current_song_id