Obtain multiple coordinates from a function at a particular value

I have a function of the type:

F[{x_,y_}] := x^2 + y^2

One can plot this function using Plot3D:

Plot3D[F[{x,y}], {x, -2, 2}, {y, -2, 2}]

If one plots the function, it is clear that F[{x,y}] = 6 at more than one set of coordinates.

How can I obtain all sets of coordinates for which F[{x,y}] = 6?

Thanks,
Stuart.

=================

=================

2 Answers
2

=================

Well there is a nice way to extract points:

mYcp = ContourPlot[x^2 + y^2 == 6, {x, -3, 3}, {y, -3, 3}]

Short[Cases[Normal@mYcp, Line[x_] :> x, Infinity], 20]

{{{-1.07143,-2.20209},{-1.1106,-2.18203},{-1.17857,-2.14721},{-1.18634,-2.14286},{-1.24885,-2.10599},{-1.28571,-2.08271},{-1.38018,-2.02304},{-1.47143,-1.95714},{-1.5,-1.93609},{-1.50433,-1.9329},{-1.50952,-1.92857},{-1.62121,-1.8355},{-1.71429,-1.7479},{-1.7316,-1.7316},{-1.7479,-1.71429},<<246>>,{-0.289216,-2.43207},{-0.321429,-2.42778},{-0.363553,-2.42216},{-0.383423,-2.41914},{-0.428571,-2.41111},{-0.473545,-2.40212},{-0.634454,-2.36555},{-0.642857,-2.36335},{-0.647783,-2.36207},{-0.663265,-2.35714},{-0.857143,-2.29252},{-0.961538,-2.25275},{-0.965438,-2.25115},{-0.968045,-2.25},{-1.07143,-2.20209}}}

  

 

wow great ! thanks for sharing it, +1
– Ali Hashmi
Mar 25 at 10:52

  

 

Nice, thanks for the solution.
– user14424
Mar 25 at 11:01

Perhaps not a good job but the closest i can get to:

plot = Reap[ContourPlot[F[{x, y}], {x, -3, 3}, {y, -3, 3},
EvaluationMonitor :> If[5.95 < F[{x, y}] < 6, Sow[{x, y, F[{x, y}]}],]]][[2,1]] // #[[All, {1, 2}]] & //ListPlot[#, PlotStyle -> Red] &

Show[ContourPlot[F[{x, y}] == 6, {x, -3, 3}, {y, -3, 3}], plot]

  

 

There are certainly numerical errors associated with the way i extracted points from the plot. however, if accuracy is not a big issue, the answers will be quite reasonable
– Ali Hashmi
Mar 25 at 8:55

  

 

Hi Ali, thanks for your answer. The example I posted was a much simpler function that the one I am actually dealing with. I have now tried your approach on my function and the results don’t look too bad. Do you have any more ideas on how to improve the accuracy? Thanks, Stuart.
– user14424
Mar 25 at 9:26

  

 

Or alternatively, incorporate more points?
– user14424
Mar 25 at 9:27

  

 

search for the question titled, “getting a list of accurate coordinates from a plot”. I think someone used a mouse event to get all the coordinates by hovering the mouse over the plot. It may be more reasonable
– Ali Hashmi
Mar 25 at 9:37

  

 

Hi Ali, thanks for the help again. Looking back at your previous answer the contour plot is completely sufficient. Thanks for your help. Cheers, Stuart.
– user14424
Mar 25 at 10:31