Total Error of the Best-Fit Line
Aldervale Instruments calibrates bench scales. A technician places a set of reference weights on the pan and records what the instrument reported for each, paired by position. The reference set is not always complete - a missing weight leaves a gap in the run, and the readings jump straight over it.
The readings rarely sit on any straight line, so no calibration curve will hit every point. The tolerance spec is written against the total leftover error once the best straight-line calibration has been applied, and that is the figure the sign-off sheet needs. One sheet is produced per scale.
Task: Print the sum of squared residuals for the least-squares line predicting the reported readings from the reference weights - each reported reading minus the value the line gives at that reference weight, squared, then totalled over every point - rounded to 2 decimals.
Input
Two lines. The first holds the reference weights placed on the pan, whole numbers separated by single spaces, in increasing order. The second holds what the instrument reported for each, in the same order. Both lines hold the same number of entries, and there are at least three.
Output
One line holding the total leftover error, rounded to 2 decimals and printed the way Python prints a float - 1.61, and 0.0 for a scale that sits exactly on a line.
Example:
Input:
1 2 3 4 6
2 3 5 7 8
Output:
1.61
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in