Calculating profit maximizing output