# Intersection of two parabolas where one is vertex shifted

1. May 26, 2015

### curiouschris

Not a homework question but this seems to be the appropriate place...

1. The problem statement, all variables and given/known data

I would like to be able to calculate the intersections of two parabola's which accounts for one or both of the parabola's being shifted along the x axis

I have written an excel vba function to do this and it all works fine as long as the parabola's are in the form of $ax^2+bx+c$

If I try to use $a(x-h)^2+bx+c$ I get lost

I have included the VBA function so you can see my working out
Code (Text):

Function QQInterceptX(a1, b1, c1, a2, b2, c2, pos)
' returns the x intercept
' y1=a1x^2+b1x+c1
' y2=a2x^2+b2x+c2
' when they intersect then the following is true
' a2x^2+b2x+c2=a1x^2+b1x+c1 as the y values are equivalent
' using algebra we get the following
' x=(a1x^2 - a2x^2) + (b1x - b2x) + (c1 - c2)
' x=(a1-a2)x^2 + (b1-b2)x + (c1-c2)
' we can then solve using the quadtratic formula
' x = (-(b1-b2) +/- sqrt((b1-b2)^2 - 4*(a1-a2)*(c1-c2)))/(2*(a1-a2))
' check for div by 0
If ((a1 - a2) <> 0) Then
' return the positive x intercept
If (pos) Then
QQInterceptX = (-(b1 - b2) + Sqr((b1 - b2) ^ 2 - 4 * (a1 - a2) * (c1 - c2))) / (2 * (a1 - a2))
Else
QQInterceptX = (-(b1 - b2) - Sqr((b1 - b2) ^ 2 - 4 * (a1 - a2) * (c1 - c2))) / (2 * (a1 - a2))
End If
Else
QQInterceptX = CVErr(xlErrNA)
End If
2. Relevant equations
An example is the following equations

$$x^2+138x+317$$
$$(x -33.33167)^2+2222$$

3. The attempt at a solution

I have attempted to resolve this myself but find my fingers hovering over the keyboard and I am sure the look of a stunned mullet on my face.

My online searches have produced zilch examples of what I am trying to do.

Its the step to the quadratic formula that loses me.

The best I could do is the following but my div by zero test fails as it does not take into account x (which is not in the divisor) So I am guessing I can't use the quadratic formula but I am not sure what else to use...

$$x = (-(b1-b2) +/- sqrt((b1-b2)^2 - 4*(a1-a2)*(c1-c2)))/(2*(a1-a2)) + (h1-h2)$$

To get me to the point of creating the VBA function I used this resource
http://zonalandeducation.com/mmts/i...woParabollas1/intersectionOfTwoParabolas1.htm

2. May 26, 2015

### Staff: Mentor

Neither of these is an equation -- no = in either.

Are these equations?
x2 + 138x + 317 = 0
(x - 33.33167)2 + 2222 = 0

If so, I would solve for x in the second equation, and substitute that value in the first equation.

3. May 27, 2015

### Ray Vickson

Either expand out $a(x-h)^2 +bx+c$ to $ax^2 + (b - 2ah)x + (c+h^2) = ax^2 + Bx + C$, or else write $a(x-h)^2 + bx + c$ as $a(x-h)^2 +b(x-h) + (c+bh)$ and use $x-h$ as the variable in place of $x$.

4. May 27, 2015

### curiouschris

Yes you are correct I should have added $=0$

Am I missing something? I don't see how that gives helps me find the intersection of the two parabola's

5. May 27, 2015

### curiouschris

Ummm. Still thinking about this. not sure I follow. I will try and work it through a bit later.

6. May 27, 2015

### ehild

These are functions, and you can write that $$y=x^2+138x+317$$ and $$(x -33.33167)^2+2222$$.
They intersect at a point (x,y ) which satisfies both equations. So you can write an equation for x by equating the y-s.
$$x^2+138x+317=(x -33.33167)^2+2222$$. Expand the square at the right side, collect the terms of equal power of x, and solve.

7. May 27, 2015

### Staff: Mentor

You're looking for points (x, y) that satisfy both equations.

Looking at your second equation again, and more closely, you have this:
(x - 33.33167)2 + 2222 = 0

As it turns out, this equation has no real solutions, since (x - 33.33167)2 is always greater than or equal to zero. We can't add a nonnegative number to 2222 to get zero. Since you can't solve for x in this equation, my earlier suggestion is no help. What you have here is a parabola that opens up, and whose vertex (low point) is above the x-axis.

8. May 27, 2015

### HallsofIvy

Staff Emeritus
You seem to still not understand the question posed. Where $(x - 33.33167)^2 + 2222 = 0$ is irrelevant.

The question is to determine where the two parabolas, $y= (x - 33.33167)^2 + 2222$ and $y= x^2 + 138x + 317$.
The equation we need to solve is $(x - 33.33167)^2 + 2222= x^2 + 138x + 317$ as ehild said.

"Expanding" that first part is not all that difficult: $x^2- 66.66334x+ 1111.0002249889+ 2222= x^2+ 138x+ 317$.

9. May 27, 2015

### Staff: Mentor

If this is directed to me, yes I understand that that equation is irrelevant. That's why I said that my earlier suggestion was no help.

10. May 27, 2015

### Ray Vickson

Suppose you want to find the intersection of $f_1 =a x^2 + b x + c$ and $f_2 = a(x-h)^2 + r x + s$, with the exact some $a$ in both. In that case your algorithm is doomed to failure, because the equation $f_1 = f_2$ has only a single root. That is, when $a_1 = a_2$ your algorithm should not declare an error; rather, it should go to an alternative branch where a different calculation is performed to find the single point of intersection.

If $a_1 \neq a_2$ but $|a_1 - a_2|$ is very small, you could have a lot of trouble with numerical roundoff errors, so at least one of the two intersection points could be quite different from the value calculated by the algorithm as written. Basically, the issue is what happens to the two roots of $f_1 - f_2 = Ax^2 + Bx + C = 0$ when $A \to 0$. The answer is that one of them remains stable, while the other one marches off to $\pm \infty$, disappearing altogether when $A = 0$ exactly. When $A$ is numerically very close to 0 (but still finite), an ordinary application of the quadratic solution formula can be subject to fatal numerical errors, just due to finite wordlength arithmetic.

11. May 27, 2015

### curiouschris

Morning Guys

I lay in bed last night and made a mental note of my idiocy. My first attempt to write a formula was incorrect I had missed an important step. I will try again when I get a chance today

Yes that's correct the vertex is positive and open up. this is a graph of the two equations (courtesy of wolframalpha)
http://www4b.wolframalpha.com/Calculate/MSP/MSP2011c5c18f5f7895224000034a5ii4f809i4h5e?MSPStoreType=image/gif&s=8&w=448.&h=191.&cdf=RangeControl [Broken]

Thanks. I was reading the quadratics page on wikipedia on the bus this morning and realised this error. So I was pleased when you noted it because it could have caused me issues. I assumed that if the discriminant was zero then there was no solution. I will create a branch to correct for this error.

At the same time I read about the possibility of inaccuracies. I dont think this is an issue for me in what I am doing but the samples I am using are a very small subset of possible equations so I will need to check into this further.

Last edited by a moderator: May 7, 2017