polishes output of solution 2, adds solution 3; solution 3 has to be checked against MATLAB functions - I will do it tomorrow