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.

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?

share|improve this question

4 Answers 4

up vote 3 down vote accepted

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$.

share|improve this answer
    
Excellent to spot the exceptions. –  Mark Bennet May 17 at 20:58

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.

share|improve this answer

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".

share|improve this answer

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$.

share|improve this answer

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.