Intersection of two parabolas where one is vertex shifted

AI Thread Summary
The discussion revolves around calculating the intersection points of two parabolas, particularly when one is shifted along the x-axis. A VBA function was created to find these intersections in the standard form ax^2 + bx + c, but complications arise when using the vertex form a(x-h)^2 + bx + c. Participants suggest expanding the vertex form to standard form or substituting variables to simplify calculations. There is also a focus on the importance of handling cases where the coefficients of the parabolas are equal, as this can lead to numerical errors or a single intersection point. The conversation highlights the need for careful algebraic manipulation to accurately determine intersection points.
curiouschris
Messages
147
Reaction score
0
Not a homework question but this seems to be the appropriate place...

1. Homework Statement

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

Homework 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)

Attribution
To get me to the point of creating the VBA function I used this resource
http://zonalandeducation.com/mmts/i...woParabollas1/intersectionOfTwoParabolas1.htm
 
Physics news on Phys.org
curiouschris said:
Not a homework question but this seems to be the appropriate place...

1. Homework Statement

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

Homework Equations


An example is the following equations

x^2+138x+317
(x -33.33167)^2+2222
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.

curiouschris said:

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)

Attribution
To get me to the point of creating the VBA function I used this resource
http://zonalandeducation.com/mmts/i...woParabollas1/intersectionOfTwoParabolas1.htm
 
curiouschris said:
Not a homework question but this seems to be the appropriate place...

1. Homework Statement

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

Homework 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)

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

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##.
 
Mark44 said:
Neither of these is an equation -- no = in either.

Are these equations?
x2 + 138x + 317 = 0
(x - 33.33167)2 + 2222 = 0
Yes you are correct I should have added =0

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

Am I missing something? I don't see how that gives helps me find the intersection of the two parabola's
 
Ray Vickson said:
Either expand out a(xh)2+bx+ca(x-h)^2 +bx+c to ax2+(b−2ah)x+(c+h2)=ax2+Bx+Cax^2 + (b - 2ah)x + (c+h^2) = ax^2 + Bx + C, or else write a(xh)2+bx+ca(x-h)^2 + bx + c as a(xh)2+b(xh)+(c+bh)a(x-h)^2 +b(x-h) + (c+bh) and use xhx-h as the variable in place of xx.

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

1. Homework Statement

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

Homework Equations


An example is the following equations

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

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.
 
Mark44 said:
If so, I would solve for x in the second equation, and substitute that value in the first equation.

curiouschris said:
Am I missing something? I don't see how that gives helps me find the intersection of the two parabola's
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.
 
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.
 
HallsOfIvy said:
You seem to still not understand the question posed. Where (x - 33.33167)^2 + 2222 = 0 is irrelevant.
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
curiouschris said:
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

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

Mark44 said:
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.

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

Ray Vickson said:
Suppose you want to find the intersection of f1=ax2+bx+cf_1 =a x^2 + b x + c and f2=a(xh)2+rx+sf_2 = a(x-h)^2 + r x + s, with the exact some aa in both. In that case your algorithm is doomed to failure, because the equation f1=f2f_1 = f_2 has only a single root. That is, when a1=a2a_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.

Thanks. I was reading the quadratics page on wikipedia on the bus this morning and realized 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 don't 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:
Back
Top