polynomials - What is the Numerically Stable Way to Compute the Coefficients of a Quadratic Function from Three Points -


i compute coefficients a0, a1, , a2 of quadradic function (polynomial of degree 2) given 3 points (x0, y0), (x1, y1), , (x2, y2), yi = a0 + a1*xi + a2*xi*xi?

i have tried following 2 formulas, not impressed precision of output

final double x0mx1, x0mx2, x1mx2, t0, t1, t2; double a2, a1, a0;  x0mx1 = (x0 - x1); x0mx2 = (x0 - x2); x1mx2 = (x1 - x2);   // method 1 t0 = (y0 / (x0mx1 * x0mx2)); t1 = (y1 / (-x0mx1 * x1mx2)); t2 = (y2 / (x0mx2 * x1mx2));  a2 = (t0 + t1 + t2); a1 = -((t0 * (x1 + x2)) + (t1 * (x0 + x2)) + (t2 * (x0 + x1))); a0 = (t0 * x1 * x2) + (t1 * x0 * x2) + (t2 * x0 * x1);  // method 2 a2 = ((((y1 - y0) * (x0mx2)) + ((y2 - y0) * ((-x0mx1)))) /                 (((x0mx2) * ((x1 * x1) - (x0 * x0)))                 + (((-x0mx1)) * ((x2 * x2) - (x0 * x0))))); a1 = (((y1 - y0) - (a2 * ((x1 * x1) - (x0 * x0)))) / ((-x0mx1))); a0 = y0 - (a2 * x0 * x0) - (a1 * x0); 

the results sort of fit, i.e., seem within +/- 1e-5 * max{ |a0'|, |a1'|, |a2'| } window of real solution a0', a1', , a2'.

is there better, more numerically stable way compute coefficients?

i using java, btw, although think not matter.

cheers, thomas.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -