I'm trying to find all possible cubic equations that can be found from two scenarios.

The first scenario is a lot like the one I asked a couple of days ago on Stack Overflow, found here: https://stackoverflow.com/questions/31909731/finding-all-possible-quadratic-equations-from-two-points

Except this time, I have three static points, along with one dynamic integer variable. The three points represent points that all qualifying cubic functions must pass through, and the dynamic variable is what changes the shape of the line.

I'm really not sure where to begin with this.

The second scenario is quite a bit different, in which there are two static points, and then there are two dynamic integer variables. The two points represent points that all qualifying cubic functions should be able to pass through, and the two dynamic variables change the shape of the line, while keeping the line within the two points.

I think that I have an idea on how to solve this, but I just wanted to make sure that it was legitimate. I was going to solve pretty much exactly the way the quadratic situation was found, and just bundle the x cubed and x squared parts together.

Basically, I want to find the 2 general equations that express all equations that can be found from the above scenarios, please.


Call the four points $(x_i,y_i): 1\le i\le 4$

Consider $$p_1(x)=\frac{(x-x_2)(x-x_3)(x-x_4)}{(x_1-x_2)(x_1-x_3)(x_1-x_4)}$$with $p_1(x_1)=1$ and $p_1(x_2)=p_1(x_3)=p_1(x_4)=0$. You can create similar expressions $p_i(x)$ for each $i$.

Now form $$p(x)=y_1p_1(x)+y_2p(x_2)+y_3p(x_3)+y_4p(x_4)$$

The form of the $p_i(x)$ ensures that $p(x_i)=y_i$.

This can be treated with one or two points as variables rather than fixed points. The method is known as Lagrange Interpolation.

Note that this gives a cubic polynomial (or could be lower degree if coefficients cancel) passing through the four points. If $q(x)$ is another cubic polynomial passing through the same four points, the $p(x)-q(x)$ is at most cubic and has at least four roots, and must therefore be zero.

Any other method for finding the relevant cubic will therefore give the same result, possibly in a different form.

| cite | improve this answer | |
  • $\begingroup$ I think I get how this works, but if one or two points are used as the dynamic variables, wouldn't that double the number of variables per? Since each point has an x and a y that could be different, which would thus make 2/4 dynamic variables? $\endgroup$ – gamehen Aug 13 '15 at 16:25
  • $\begingroup$ @gamehen I am not sure about your context and what you mean by dynamic variables. However if you are changing the values of $x_i$ at fixed values of $y_i$ then the $y_i$ are constants. If you are changing both $x_i$ and $y_i$ at two points, then naturally four things are changing. If $x_i$ and $y_i$ depend on a parameter, feed that into the equation. But the equation of the cubic will be the one I've given. $\endgroup$ – Mark Bennet Aug 13 '15 at 16:31
  • $\begingroup$ Oh I see. I was originally looking for an equation that has just three/two points and one/two variables, but if this works then that's fine. As for the context, I'm trying to write the algorithm for a program that I'm writing. I've done a previous version for quadratics, which you can see here: jsfiddle.net/c36g0w73 , and now I'm trying to change it to work for cubics as well, within the two given scenarios above. $\endgroup$ – gamehen Aug 13 '15 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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