implemented the formulas from ex4.pdf & submitted