2
$\begingroup$

I recently ran through an algebraic solution for the intersection point(s) of two parabolas $ax^2 + bx + c$ and $dx^2 + ex + f$ so that I could write a program that solved for them. The math goes like this:

$$ ax^2 - dx^2 + bx - ex + c - f = 0 \\ x^2(a - d) + x(b - e) = f - c \\ x^2(a - d) + x(b - e) + \frac{(b - e)^2}{4(a - d)} = f - c + \frac{(b - e)^2}{4(a - d)} \\ (x\sqrt{a - d} + \frac{b - e}{2\sqrt{a - d}})^2 = f - c + \frac{(b - e)^2}{4(a - d)} \\ (a - d)(x + \frac{b - e}{2(a - d)})^2 = f - c + \frac{(b - e)^2}{4(a - d)} \\ x + \frac{b - e}{2(a - d)} = \sqrt{\frac{f - c + \frac{(b - e)^2}{a - d}}{a - d}} \\ x = \pm\sqrt{\frac{f - c + \frac{(b - e)^2}{a - d}}{a - d}} - \frac{b - e}{2(a - d)} \\ $$

Then solving for $y$ is as simple as plugging $x$ into one of the equations.

$$ y = ax^2 + bx + c $$

Is my solution for $x$ and $y$ correct? Is there a better way to solve for the intersection points?

$\endgroup$

4 Answers 4

4
$\begingroup$

You lost a factor $4$ somewhere. You can simply rewrite your problem as

$$(a-d)x^2+(b-e)x+(c-f)=0$$

and use the standard formula for a quadratic equation, i.e.

$$x=-\frac{b-e}{2(a-d)}\pm\sqrt{\frac{(b-e)^2}{4(a-d)^2}-\frac{c-f}{a-d}}$$

Before evaluating this equation, you need to check if $a-d=0$, in which case

$$x=\frac{f-c}{b-e}$$

In this case you of course need to check if $b-e=0$.

$\endgroup$
1
  • $\begingroup$ Excellent to spot the exceptions. $\endgroup$ Commented May 17, 2014 at 20:58
1
$\begingroup$

You should recognise a form of the quadratic formula:$$(a-d)x^2+(b-e)x+(c-f)=0$$

which gives $$x=\frac {-(b-e)\pm \sqrt {(b-e)^2-4(a-d)(c-f)}}{2(a-d)}$$

This is the same as yours except for a missing factor of $\frac 14$ under your square root, which you lost when you took the square root near the end.

$\endgroup$
1
$\begingroup$

All the other answers are fine from a mathematical point of view, but they ignore the fact that using the quadratic formula is a very bad way to solve quadratic equations in computer code (using floating point arithmetic).

The problem arises when one of the roots is near zero. In this case, either the "$+$" or the "$-$" formula of the $\pm$ will cause you to subtract two numbers that are nearly equal, and this will result in catastrophic cancellation error. The problem is illustrated here, and the well-known solutions are described.

For other interesting examples, see George Forsythe's famous paper "Why a Math Book is not Enough".

$\endgroup$
0
$\begingroup$

Well, you somehow lost the factor of 4, otherwise seems valid. As you are going to write a program for this, you should also write a solution gfor the case $a=d$ and deal with the case the radical is zero or does not exist.

Actually, you did not have to write all this, as people usually know the solution of quadratic equation (isn't it school material?). For $ax^2 + bx +c = 0$ usually _the discriminant _$D=b^2 - 4ac$ is calculated, and then $x_{1,2}$ are given as $\frac {-b ±\sqrt D}{2a}$. If D=0 then the only sulution $-\frac b {2a}$ exists, and if $D<0$ there are no real solutions (as $\sqrt D$ is not a real number then or does not exist if we only work with real numbers). Then just use $a-d,b-e$ and $c-f$ as coefficients in the general solution formula. A separate solution for the case $a=d$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .