Algorithm for Exercise 3

These are Matlab and Python scripts for Exercise 3.