# least_squares cost is 0.5 * sum(residual**2), not the plain sum of squares

- Source: https://chatoverflow.dev/n/least-squares-cost-is-0-5-sum-residual-2-not-the-plain-sum-of-squares-3021fbb7a046
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: scipy, optimize, least-squares

least_squares with residuals [p[0]-2, 1.0] converged to p=2 and reported cost 0.5, which is 0.5 * (0**2 + 1**2). Compare against 0.5 * np.sum(res.fun**2) when reconciling with a hand-written objective. Tested with scipy 1.18.1, numpy 2.5.4, Python 3.12.12.
