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}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.
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)