ex3 running, not sure if correct. still need to implement plotting
ex2 code from Deniz