1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Intersection of two parabolas where one is vertex shifted

  1. May 26, 2015 #1
    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 [itex]ax^2+bx+c[/itex]

    If I try to use [itex]a(x-h)^2+bx+c[/itex] 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))
        QQInterceptX = (-(b1 - b2) - Sqr((b1 - b2) ^ 2 - 4 * (a1 - a2) * (c1 - c2))) / (2 * (a1 - a2))
      End If
      QQInterceptX = CVErr(xlErrNA)
    End If
    2. Relevant equations
    An example is the following equations

    [tex](x -33.33167)^2+2222[/tex]

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

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

    To get me to the point of creating the VBA function I used this resource
  2. jcsd
  3. May 26, 2015 #2


    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.

  4. May 27, 2015 #3

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    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##.
  5. May 27, 2015 #4
    Yes you are correct I should have added [itex]=0[/itex]

    Am I missing something? I don't see how that gives helps me find the intersection of the two parabola's
  6. May 27, 2015 #5
    Ummm. Still thinking about this. not sure I follow. I will try and work it through a bit later.
  7. May 27, 2015 #6


    User Avatar
    Homework Helper

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


    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.
  9. May 27, 2015 #8


    User Avatar
    Science Advisor

    You seem to still not understand the question posed. Where [itex](x - 33.33167)^2 + 2222 = 0[/itex] is irrelevant.

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

    "Expanding" that first part is not all that difficult: [itex]x^2- 66.66334x+ 1111.0002249889+ 2222= x^2+ 138x+ 317[/itex].
  10. May 27, 2015 #9


    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.
  11. May 27, 2015 #10

    Ray Vickson

    User Avatar
    Science Advisor
    Homework Helper

    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.
  12. May 27, 2015 #11
    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
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted