Say I have a curve $$y = ax^3 + bx^2 + cx + d.$$
I don't know $a$, $b$, $c$ or $d$, but I do know the $(x,y)$ values of four points on this curve.
How can the values of $a$, $b$, $c$ and $d$ be calculated? (Preferably in terms understandable by a novice.)
Follow-up to MJD's answer.
Hello. Many thanks for the informative answer but I'm stuck following it.
(A brief digression about where I'm coming from in asking this question.)
I'm an amateur video-maker and I want to show a oscilloscope-esque monitor with a changing cubic curve. To do this, I'd write a computer program that randomly picks four points and calculates a cubic curve which goes through those points. The scope quickly changes, with each frame having moved each of the four points randomly a little bit and the curve redrawn.
During the play, the hero discovers where one of the points on the curve should be and fixes that point. The other three points continue to move but the curve always remains going through that fixed point.
Later on, the hero discovers another point and fixes it. Now, the curve containues to wobble about but remains fixed at those two points.
The hero continues to discover all four points and finally the curve is locked and saves the day.
(End of digression)
For my program to work, I need to write a function that takes four x/y points (fixed or floating, doesn't matter) and returns the a,b,c and d values that describe that cubic curve.
Going back to MJD's answer, I followed the steps as outlined below. For the x/y inputs, I'm using eight letters rather than using MJD's sub-scripts as I can type these.
Here's the four starting equations. a,b,c,d are unknown. (k,f),(m,g),(n,h),(p,j) are known.
f = ak³ + bk² + ck + d g = am³ + bm² + cm + d h = an³ + bn² + cn + d j = ap³ + bp² + cp + d
For each equation (except the first), subtract the one above.
(g-f) = am³ - ak³ + bm² - bk² + cm - ck + d - d (h-g) = an³ - am³ + bn² - bm² + cn - cm + d - d (j-h) = ap³ - an³ + bp² - bn² + cp - cn + d - d
(g-f) = a(m³-k³) + b(m²-k²) + c(m-k) + (d-d) (h-g) = a(n³-m³) + b(n²-m²) + c(n-m) + (d-d) (j-h) = a(p³-n³) + b(p²-n²) + c(p-n) + (d-d)
Remove +(d-d) as this must be zero.
(g-f) = a(m³-k³) + b(m²-k²) + c(m-k) (h-g) = a(n³-m³) + b(n²-m²) + c(n-m) (j-h) = a(p³-n³) + b(p²-n²) + c(p-n)
Doing great so far! Now do the same with the three remaining equations to leave two.
(h-g)-(g-f) = a(n³-m³) - a(m³-k³) + b(n²-m²) - b(m²-k²) + c(n-m) - c(m-k) (j-h)-(h-g) = a(p³-n³) - a(n³-m³) + b(p²-n²) - b(h²-m²) + c(p-n) - c(n-m)
(f-2g+h) = a(k³-2m³+n³) + b(k²-2m²+n²) + c(k-2m+n) (g-2h+j) = a(m³-2n³+p³) + b(m²-2n²+p²) + c(m-2n+p)
Here, I'm meant to eliminate the appearances of the unknown 'c' from these equations because in each case, c is being multiplied by zero. However, this step only works because of the x values chosen in the original answer; 1,2,3,4. Both (3-2*2+1) and (4-2*3+2) happen to equal zero.
How can I proceed from this point if my x values are not uniformly spaced?