Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Apologies for the poor question. I have had more negative feedback for this than positive feedback for questions where I put several nicely drawn images!

So, here it is...

Edit:

I have a formula to work out the coefficients of a quadratic when given 3 plots on the line.

quadraticCoefficient = (((p2.y - p1.y) x (p1.x - p3.x)) + ((p3.y - p1.y) x (p2.x - p1.x))) / ((p1.x - p3.x) x ((p2.x x p2.x) - (p1.x x p1.x)) + ((p2.x - p1.x) x ((p3.x x p3.x) - (p1.x x p1.x))));
linearCoefficient = ((p2.y - p1.y) - quadraticCoefficient x ((p2.x x p2.x) - (p1.x x p1.x))) / (p2.x - p1.x);
fixedTerm = p1.y - (quadraticCoefficient x p1.x x p1.x) - (linearCoefficient x p1.x);

Where p1, p2 and p3 are all plots along the line.

I am interested in a similar formula that would allow me to work out each coefficient of a cubic for 4 given points.

Original:

Here is some c++ I have to find the coefficients of a quadratic.

RS_EquationQ getEquationQ(const RS_PlotF p1, const RS_PlotF p2, const RS_PlotF p3) {
    RS_EquationQ e;
    e.quadraticCoefficient = (((p2.y - p1.y) * (p1.x - p3.x)) + ((p3.y - p1.y) * (p2.x - p1.x))) / ((p1.x - p3.x) * ((p2.x * p2.x) - (p1.x * p1.x)) + ((p2.x - p1.x) * ((p3.x * p3.x) - (p1.x * p1.x))));
    e.linearCoefficient = ((p2.y - p1.y) - e.quadraticCoefficient * ((p2.x * p2.x) - (p1.x * p1.x))) / (p2.x - p1.x);
    e.fixedTerm = p1.y - (e.quadraticCoefficient * p1.x * p1.x) - (e.linearCoefficient * p1.x);
    return e;
}

I would like to write an equivilent function for a cubic. If anyone could point me in the direction of a formula (or appropriate reading material) ...I would appreciate it!

share|improve this question
2  
-1 It would be much more helpful to describe the problem you are trying to solve, rather than post uncommented and undocumented code. It looks like you are doing polynomial interpolation. If so, have you looked on the web? There are many resources. –  Ross Millikan Sep 18 '12 at 2:31
1  
I could come up with lots of equivalent functions if I knew what "equivalent" meant here. What's the context? What are you trying to achieve? –  Rick Decker Sep 18 '12 at 2:31
2  
Would help me if I could see the math involved, other than code, I don't know C++. Maybe try asking on a programming q/a site. –  yiyi Sep 18 '12 at 2:35
1  
I agree with the above comments that this is not at all the appropriate form for this question. That said, if I interpret your variable names correctly, you fit the parabola with equation $$ax^2+bx+c$$ through three points, $p_1=(x_1,y_1), p_2=(x_2,y_2), p_3=(x_3,y_3)$ and propose to do so with the equations $$ a=\frac{((y_2-y_1)(x_1-x_3))+((y_3-y_1)(x_2-x_2))}{(x_1-x_3)(x_2^2-x_1^2)+(x_2-x‌​_1)(x_3^2-x_1^2)}$$ $$ b= \frac{(y_2-y_1)-a(x_2^2-x_1^2)}{x_2-x_1} $$ $$c = y_1-ax_1^2 - bx_1 $$ and are asking for a similar equation to fit a cubic through three (or four?) points. –  Drew Christianson Sep 18 '12 at 3:27
add comment

1 Answer

Following on the intepretation of your question in my comment, the you can fit a cubic over 4 points using the Vandermode matrix for $n = 3$ : $$\left[\begin{array}[ccccc] & x_1^3 & x_1^2 & x_1 &1 \\ x_2^3 & x_2^2 & x_2 &1\\ x_3^3&x_3^2 & x_3 &1\\ x_4^3&x_4^2&x_4&1 \end{array}\right] \left[\begin{array}[cc] & a_3 \\ a_2 \\ a_1 \\ a_0 \end{array}\right] =\left[\begin{array}[cc] & y_1 \\ y_2 \\ y_3 \\ y_4 \end{array}\right] $$ At this point, you can just row reduce the obvious matrix describing the obvious system of four equations in four unknowns. Or, if you want to stick with only the points and basic operations, you can just solve the system explicitly for the four coefficients.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.