Compute J-cost function and data plotting.