5
$\begingroup$

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] 
$\endgroup$
4
  • 2
    $\begingroup$ Isn't NSolve[ {(x^2 + y^2 - 4) == 0 , (y - x^2 + 2 x - 1) == 0}, {x,y}, Reals] enough for you? $\endgroup$ Commented Jan 2, 2015 at 11:01
  • $\begingroup$ related mathematica.stackexchange.com/questions/9928/… and mathematica.stackexchange.com/questions/275/… $\endgroup$ Commented Jan 2, 2015 at 11:26
  • $\begingroup$ @b.gatessucks it seems so… see post below? $\endgroup$ Commented Jan 2, 2015 at 11:35
  • $\begingroup$ Link to a 96320 post for reference. $\endgroup$ Commented Dec 26, 2024 at 4:44

4 Answers 4

3
$\begingroup$

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

enter image description here

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 *) 
$\endgroup$
5
$\begingroup$

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

Mathematica graphics

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

Mathematica graphics

$\endgroup$
3
$\begingroup$

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

enter image description here

See also: Marking points of intersection between two curves

Graphics`Mesh`FindIntersections

Using the function Graphics`Mesh`FindIntersections to find the intersections:

Graphics`Mesh`MeshInit[]; 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[Graphics`Mesh`FindIntersections[Normal @ cp]]}] 

enter image description here

$\endgroup$
1
$\begingroup$

Using Region functionality:

r1 = ImplicitRegion[x^2 + y^2 == 4, {x, y}]; r2 = ImplicitRegion[y - x^2 + 2 x == 1, {{x, -2, 3}, {y, -2, 3}}]; ri = RegionIntersection[r1, r2]; Show[ Region[Style[r1, Blue]] , Region[Style[r2, Black]] , Region[Style[ri, Directive @@ {AbsolutePointSize[6], Red}]] , Frame -> True ] 

A demo of RegionIntersection

ri // DiscretizeRegion // MeshPrimitives[#, 0] & 

{Point[{1.85894, 0.737785}], Point[{-0.399864, 1.95962}]

}


EDIT

In order to find the area of intersection, the following can be done:

rfill = ImplicitRegion[x^2 + y^2 <= 4 > y - x^2 + 2 x >= 1, {x, y}]; Show[ Region[Style[r1, Blue]] , Region[Style[r2, Black]] , Region[Style[ri, Directive @@ {AbsolutePointSize[6], Red}]] , Region[Style[rfill, HatchFilling[]]] , Frame -> True ] 

Filling region

Area[rfill] // N 

2.74044

$\endgroup$
2
  • $\begingroup$ Nice, thanks. If we take a self intersecting curve like the Bernoulli Lemniscate intersecting a circle, would it still work for total area or net area of these loops? $\endgroup$ Commented Dec 26, 2024 at 3:39
  • $\begingroup$ May be using the ParametricRegion command. There is information available in the Entity system about the curve. Also, there are many questions on the site covering this topic. $\endgroup$ Commented Dec 26, 2024 at 3:52

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.