phys_581.assignment_1#

Assignment 1

Functions#

play_monty_hall([switch])

Return True if the contestant wins one round of Monty Hall.

fib(n)

Return the nth Fibonacci number.

lambertw(z[, k])

Return \(w\) from the k'th branch of the LambertW function.

zeta(s)

Return the Riemann zeta function at s.

derivative(f, x[, d])

Return the d'th derivative of f(x) at x.

Module Contents#

play_monty_hall(switch=False)#

Return True if the contestant wins one round of Monty Hall.

Parameters:

switch (bool) – If True, then switch doors, otherwise stick with the original door.

fib(n)#

Return the nth Fibonacci number.

lambertw(z, k=-1)#

Return \(w\) from the k’th branch of the LambertW function.

\[z = we^w, \qquad w = W_k(z).\]
Parameters:
  • z (float, array_like) – Argument. You can assume that z >= -exp(-1) and that z <= 0 if k == -1. Raise ValueError otherwise (unless your code correctly extends \(W(z)\) to the complex plane).

  • k ([0, -1]) – Branch. If k == 0, then return the solution \(w>-1\), otherwise if k == -1, return the solution \(w < -1\)

Notes

Do not use a canned implementation, even if you find one in SciPy. Write your own version.

zeta(s)#

Return the Riemann zeta function at s.

\[\zeta(s) = \sum_{1}^{\infty} \frac{1}{n^{s}}.\]
Parameters:

s (float) – Argument of the zeta function.

derivative(f, x, d=0)#

Return the d’th derivative of f(x) at x.

Parameters:
  • f (function) – The function to take the derivative of.

  • x (float) – Where to take the derivative.

  • d (int) – Which derivative to take. d=0 just evaluates the function.