All problems

Fitting a Polynomial Curve With order

hardPythonSeabornorder

Calder Engineering's readings for one component do not lie on a straight line at all: they bend. A straight fit through them would be wrong everywhere and confidently so, therefore the rig chart fits a curve instead. The sign-off sheet quotes the number that controls how sharply that curve bends, and its sign, because a curve that bends upwards and one that bends downwards mean opposite things.

Task: Print the squared term's coefficient of the best-fit curve.

Input

The first line holds one integer n, the number of readings, where 3 <= n <= 1000. Then come n lines, each holding a reading's x and y separated by a single space, x first. At least three different x values appear.

Output

One line, rounded to 2 decimal places. The curve is of the form a times x squared, plus b times x, plus c, with all three fitted by least squares against the up-and-down gaps to the readings. Print a, the coefficient of the squared term -- not b, not c.

Example:

Input:
5
-2 4
-1 1
0 0
1 1
2 4

Output:
1.00

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

Discussion

Sign in to join the discussion — reading is open to everyone.

Loading comments…