Improved code from numerial to analytical solution