A. Fibonacci series

The Fibonacci series is defined as follows:

\begin{align} x_0 &= 1 \\ x_1 &= 1 \\ x_n &= x_{n-2} + x_{n-1} \ \forall n \geq 2 \end{align}
  1. Define a function that returns the $n$-th Fibonacci number. Discuss what happens when $n$ gets big enough. By the way, your code should give an approximate result even for big $n$.
  2. Define a function that returns the last 4 digits of the $n$-th Fibonacci number, no matter how big $n$ is.

B. Eigenvalues

To get the eigenvalues of a $2 \times 2$ matrix, you need to solve the following equation (with the unknown $\lambda$):

\begin{equation} \det(A - \lambda I) = 0 \end{equation}

Write a program that finds the eigenvalues for an arbitrary $2 \times 2$ matrix.

C. Area of a triangle

Given 3 points $A$, $B$ and $C$ in the plane, with their coordinates $(a_x, a_y)$ $(b_x, b_y)$ $(c_x, c_y)$, the area of the triangle they form is given by the following formula: \begin{equation} \frac{1}{2} \left| \det \left( \begin{aligned} a_x && a_y && 1 \\ b_x && b_y && 1 \\ c_x && c_y && 1 \end{aligned} \right) \right| \end{equation}

Write a subroutine that will take as parameters three lists of 2 values, A, B and C, and will return the area of the triangle that the corresponding 3 points on a plane form.

D. Kahan summation formula

Given a list of arbitrary numbers, write a simple function to sum the elements of that list. Write a second function, using the algorithm by Kahan, (https://en.wikipedia.org/wiki/Kahan_summation_algorithm has a very nice description).

Use the function defined in the following cell to generate a list of $N$ numbers to feed into the 2 functions you've defined. Compare the results obtained with the two functions for $N = 3^k$, for all $k \leq 13$.


In [ ]:
import numpy as np
def get_numbers(N):
    return np.random.randn(N)