# Points of Intersection

How to numerically find points of intersection between pair of curves (Here,a circle and a parabola) ? Finding it a bit messy as, for a point on one curve, slope of the other is involved.

ContourPlot[ (x^2 + y^2 - 4) *( y - x^2 + 2 x - 1) == 0, {x, -4, 4}, {y, -4, 4} , ContourStyle -> {Thick, Magenta},
GridLines -> Automatic]
• Isn't NSolve[ {(x^2 + y^2 - 4) == 0 , (y - x^2 + 2 x - 1) == 0}, {x,y}, Reals] enough for you? Jan 2, 2015 at 11:01
• Jan 2, 2015 at 11:26
• @b.gatessucks it seems so… see post below? Jan 2, 2015 at 11:35

FindInstance works as well:

fi = FindInstance[(x^2 + y^2 - 4) == 0 && (y - x^2 + 2 x - 1) ==
0, {x, y}, Reals, 2] // N

{*
{x -> -0.399864, y -> 1.95962}, {x -> 1.85894, y -> 0.737785}
*}

ContourPlot[(x^2 + y^2 - 4)*(y - x^2 + 2 x - 1) == 0, {x, -4,
4}, {y, -4, 4}, ContourStyle -> {Thick, Blue},
GridLines -> Automatic,
Epilog -> {Red, PointSize[Large], Point[{x, y}] /. fi}]

And we can compare the results of FindInstance with NSolve

nsol = NSolve[{(x^2 + y^2 - 4) == 0, (y - x^2 + 2 x - 1) == 0}, {x,
y}, Reals]

{*
{x -> -0.399864, y -> 1.95962}, {x -> 1.85894, y -> 0.737785}
*}

fi == nsol
(*
True
*)

Using this great post of J.M. which defines FindAllCrossings2D

f[x_, y_] := (x^2 + y^2 - 4)
g[x_, y_] := (y - x^2 + 2 x - 1)

pts = FindAllCrossings2D[{f[x, y], g[x, y]}, {x, -7/2, 4}, {y, -9/5,
21/5}, Method -> {"Newton", "StepControl" -> "LineSearch"},
PlotPoints -> 85, WorkingPrecision -> 20] // Chop;

pl=ContourPlot[{f[x, y], g[x, y]}, {x, -7/2, 4}, {y, -9/5, 21/5},
Contours -> {0}, ContourShading -> False,
Epilog -> {AbsolutePointSize[6], Red, Point /@ pts}]

we can check it works

NSolve[{(x^2 + y^2 - 4) == 0, (y - x^2 + 2 x - 1) == 0}, {x,y}, Reals]

(* {{x->-0.399864,y->1.95962},{x->1.85894,y->0.737785}} *)

Show[pl,
Graphics[{AbsolutePointSize[12], Purple,
Point[{x, y}] /.
NSolve[{(x^2 + y^2 - 4) == 0, (y - x^2 + 2 x - 1) == 0}, {x, y},  Reals]}]]

## MeshFunctions

You can also use a combination of the options MeshFunctions and Mesh:

f[x_, y_] := (x^2 + y^2 - 4)
g[x_, y_] := (y - x^2 + 2 x - 1)

ContourPlot[{f[x, y], g[x, y]}, {x, -7/2, 4}, {y, -9/5, 21/5},
Contours -> {0}, ContourShading -> False, BaseStyle -> Thick,
MeshFunctions -> {g[#, #2] - f[#, #2] &},
Mesh -> {{{0, Directive[Red, PointSize[Large]]}}}]

## GraphicsMeshFindIntersections

Using the function GraphicsMeshFindIntersections to find the intersections:

GraphicsMeshMeshInit[];
cp = ContourPlot[{f[x, y], g[x, y]}, {x, -7/2, 4}, {y, -9/5, 21/5},
Contours -> {0}, ContourShading -> False, BaseStyle -> Thick];

Show[cp, Epilog -> {Red, PointSize[.03],
Point[GraphicsMeshFindIntersections[Normal @ cp]]}]