Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

CJ Meyer 19007361

🏠
Working from home
  • Stellenbosch, South Africa
View GitHub Profile
View tt-live-bot.py
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
View secant.py (practise)
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):
View gist:476400ca95fb53be6b90d1ec79b67c05
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