-3
$\begingroup$

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!

  • 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.2012-09-18
  • 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?2012-09-18
  • 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.2012-09-18
  • 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.2012-09-18

1 Answers 1