I'm writing a program that uses a cubic curve, and I'm trying to find the 4 formulae to give me a, b, c and d for ax3 + bx2 + cx + d = 0 for a set of data points x and y. Any help would be appreciated,

Thanks,

J.J.

Printable View

- Sep 7th 2009, 02:16 AMJ.J.Cubic formula
I'm writing a program that uses a cubic curve, and I'm trying to find the 4 formulae to give me a, b, c and d for ax3 + bx2 + cx + d = 0 for a set of data points x and y. Any help would be appreciated,

Thanks,

J.J. - Sep 7th 2009, 06:33 AMCaptainBlack
Lets suppose what you really mean is that you have a set of data points that you want to fit to a cubic:

If there are four points when you plug them into the above you get a set of four simultaneous linear equations for .

If there are more than four points the look up linear regression.

CB - Sep 7th 2009, 06:39 AMJ.J.Cubic Formula
What I'm trying to find are formulae like these ones:

(These are the formulae to get a, b + c for ax2 + bx + c = 0 given a set of x and y data points)

a = (Σy*Σx*Σx3 - Σxy*n*Σx3 - Σy*(Σx2 )2

+ Σxy*Σx*Σx2 + Σx2y*n*x2 – Σx2y*(Σx)2)

/ (n*Σx2*Σx4 – (Σx)2*Σx4 - n*(Σx3)2 + 2*Σx*Σx2*Σx3 – (Σx2)3)

b = (Σxy*n*Σx4 - Σy*Σx*Σx4 + Σy*Σx2*Σx3

- Σx2y*n*Σx3 - Σxy*(Σx2)2 + Σx2y*Σx*Σx2)

/ (n*Σx2*Σx4 – (Σx)2*Σx4 - n*(Σx3)2 + 2*Σx*Σx2*Σx3 – (Σx2)3)

c = (Σy*Σx2*Σx4 - Σxy*Σx*Σx4 - Σy*(Σx3)2

+ Σxy*Σx2*Σx3 + Σx2y*Σx*Σx3 – Σx2y*(Σx2)2)

/ (n*Σx2*Σx4 – (Σx)2*Σx4 - n*(Σx3)2 + 2*Σx*Σx2*Σx3 – (Σx2)3) - Sep 7th 2009, 08:29 AMHallsofIvy
Apparently, you are looking for the "least squares" cubic that goes "closest" to those points.

Think of it this way: you are looking for a, b, c, d such that every point satisfy

,

We can write that as the matrix equation, Ax= b:

.

Now A is a linear transformation from to and so maps into a 4 dimensional**subspace**of . That equation has a solution only if b happens to lie in that subspace (if the points happen to lie on the graph of a cubic). If not then the best we can do is to find the x in that is**closest**to b. That would mean that if x is such, the vector from b to Ax, Ax- b, must be perpendicular to that subspace and so perpendicular to every vector in it. Since every vector in that subspace can be written as Av for some v in we must have <Av, Ax- b>= 0 where "< , >" is the inner (dot) product in .

Now, some theory. If A is a linear transformation from vector space U to vector space V, then its "adjoint", A*, is the linear transformation from V back to U such that, for all u in U, v in V, <Au, v>= <u, A*v> where the inner product in V and on the right in U. Here, <Av, Ax-b>= <v, A*(Ax-b)>= 0. But now that inner product on the right is in and v can be any vector in since the inner product of A*(Ax- b) with**any**vector in (in particular with itself) is 0, we must have A*(Ax- b)= A*Ax- A*b= 0 or A*Ax= A*b and so, if the inverse exists, .

(if it exists)- is the "generalized inverse" of A. It can be shown that if A has an inverse, so does A* and so that . But even if A does not have an inverse (if it is not square as in this case) (A*A)^{-1} may exist.

Here, so

and that .

Also

Now, the tedious part is to find the inverse of that 4 by 4 matrix. That's going to involve some really messy formulas that I don't want to have to calculate! But once you have done that, a, b, c, and d are given by the components of . - Sep 8th 2009, 01:39 AMJ.J.Cubic Formula
The problem with matices is that I'm going to be writing the formulae into a computer program, which can't solve matrices, which is why I was looking for formulae like the ones above. Even a link with something that could help would be appreciated.

Thanks,

J.J. - Sep 8th 2009, 10:29 AMCaptainBlack
- Sep 9th 2009, 01:43 AMJ.J.Cubic Formula
To be honest, I'm don't know a lot about matrices, and it's been a while since I did anything involving matrices.

- Sep 9th 2009, 07:36 AMJ.J.
Say there are 4 x and y values called x1, x2, x3, x4 etc. For the first term of the A*A matrix, is that (x1^6 + x2^6 + x3^6 + x4^6) or

(x1 + x2 + x3 + x4)^6? Similarly, for the the A*b matrix, is that (x1^3 + x2^3 + x3^3 + x4^3)*(y1 + y2 + y3 + y4) or ((x1 + x2 + x3 + x4)^3)*(y1 + y2 + y3 + y4) or (x1^3*y1 + x2^3*y2 + x3^3*y3 + x4^3*y4)?

(It's been a while since I did maths using notation like this)