Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have two objects $x$ and $y$ whose position at time $t$ is given by: $$ x = a_xt^2+b_xt+c_x \\ y= a_yt^2+b_yt+c_y $$

And I want to find which (if any) values of $t$ cause $x$ to equal $y$. That is $$ (a_x-a_y)t^2+(b_x-b_y)t+(c_x-c_y) = 0 $$

This can easily be solved with quadratic equation. But what about the case when $a_x = a_y$? Now obviously this makes the problem much simpler to solve by hand! But if I were writing, lets say a simulation, where $a_x$ didn't necessarily equal $a_y$, but it could, how would I go about solving the equation? Preferably I'm looking for some sort of algorithm/equation that I can use to avoid having to write separate logic for the cases where $a_x = a_y$ and $a_x \neq a_y$.

Quick background: I have knowledge of math up to Linear Algebra (I feel a very simple answer lies here, but I can't quite work it out) and ~1/2 a course in Differential Equations (though I think that doesn't really apply here), but I'm more than willing to learn something new if it provides an easy way of solving my problem. Thanks!

share|cite|improve this question
I do not think you can write one unified solution for both cases as the quadratic solution for the standard version $ax^2+bx+c=0$ assumes that $a\ne0$. – response May 17 '13 at 22:27
If $a \ne 0$, quadratic, if $b \ne 0$, linear, else constant. So, you can do a check for that sort of nested check to know which path to take. – Amzoti May 17 '13 at 22:30
up vote 1 down vote accepted

You can write a simulation to handle both cases if you resort to numerical solutions as opposed to analytical.

1). You try using Newton-Raphson method, $x_{n+1} = x_{n}-f(x_{n})/f'(x_{n}) $. This method does not care about what the order of f is, and will solve an approximate solution regardless.

2). you do a brute force way of putting values for t, until you get zero, or as close to zero as you can at a reasonable resolution and time. (not recommended)

share|cite|improve this answer
How does the Newton-Raphson method handle functions with no 0's? – williamg May 17 '13 at 23:17
It doesn't really just needs a function. – Sason Torosean May 17 '13 at 23:39
Well what I mean is, I need to be able to identify when there is no solution. Does this method provide a way of doing that? – williamg May 17 '13 at 23:49
On second thought, I can probably determine no solutions by checking out the discriminant before hand. – williamg May 17 '13 at 23:49
good call with the discriminant! – Sason Torosean May 17 '13 at 23:53

The "true" quadratic equation $ax^2+bx+c=0$, with $a \neq 0$ has solutions $$x_{1,2}=\frac{-b \pm \sqrt{b^2-4ac}}{2a}. $$ If $a=0$, the equation reduces to the linear $bx+c=0$, which has the solution $x=\frac{-c}{b}$.

Note that one of the $x_{1,2}$ has the indeterminate form $\frac{0}{0}$ when $a=0$. (You should look at the one with the $\pm$ sign in front of the square root equal to the sign of $b$). If you apply L'Hôpital's rule for that $x$ you find that it's limiting value as $a \to 0$ is $$\frac{\frac{-\text{sgn} (b) 4c}{2 \sqrt{b^2-4ac}}}{2} \bigg|_{a=0}=\frac{-\text{sgn}(b)c}{|b|}=\frac{-c}{b}. $$ Which agrees with the true solution! The conclusion is, that even if the coefficient of $x^2$ becomes zero ($a_x=a_y$ in your case) you could change your parameters very slightly and one of the solutions from the quadratic will be very close to the true solution (The other solution can be proven to diverge as $a \to 0$).

For example consider the quadratic equation $ax^2+x-1=0$. It has solutions $$x_{1,2}=\frac{-1 \pm \sqrt{1-4a}}{2a} $$ Since $b=1$ is positive here, we focus on the solution with the plus sign $x=\frac{-1+\sqrt{1-4a}}{2a}$:

enter image description here

You can convince yourself from the graph that for $a \approx 0$ the solution approaches the correct $x=1$.

share|cite|improve this answer

Your Answer


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.