0
$\begingroup$

This question already has an answer here:

I have a ListLinePlot of some datas and a plot of a constant function. How can I find the intersection point?

My data are:

data = {{0.2*10^4, 0.57}, {0.6*10^3, 0.56}, {0.2*10^3, 0.55}, {0.6*10^2, 0.53}, 
        {0.2*10^2, 0.49}, {6, 0.44}, {2, 0.38}, {0.6, 0.33}, {0.2, 0.23}};

and I would like to find the intersection with y = 0.29.

$\endgroup$

marked as duplicate by Öskå, acl, RunnyKine, ubpdqn, Mr.Wizard Jul 16 '14 at 12:43

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 2
    $\begingroup$ Let's see a concrete example? $\endgroup$ – Öskå Jul 16 '14 at 10:28
  • $\begingroup$ I have these datas: $\endgroup$ – Ema Jul 16 '14 at 10:31
  • $\begingroup$ {{0.2*10^4, 0.57}, {0.6*10^3, 0.56}, {0.2*10^3, 0.55}, {0.6*10^2, 0.53}, {0.2*10^2, 0.49}, {6, 0.44}, {2, 0.38}, {0.6, 0.33}, {0.2, 0.23}} and i vahe done the ListLinePlot. But i have yo intersecate this plot with y=0.29. How can i find the solution? $\endgroup$ – Ema Jul 16 '14 at 10:33
  • $\begingroup$ NSolve[(0.29 - 0.23)/(x - 0.2) == (0.33 - 0.23)/(0.6 - 0.2), x] $\endgroup$ – seismatica Jul 16 '14 at 10:44
1
$\begingroup$

Using this function:

data = {{0.2*10^4, 0.57}, {0.6*10^3, 0.56}, {0.2*10^3, 0.55}, {0.6*10^2, 0.53}, 
        {0.2*10^2, 0.49}, {6, 0.44}, {2, 0.38}, {0.6, 0.33}, {0.2, 0.23}};
f = Interpolation[data, InterpolationOrder -> 1];
y[x_] := 0.29
x0 = First[x /. FindRoot[f[x] - y[x], {x, #[[1, 1]], #[[2, 1]]}] & /@ 
       Select[Partition[Sort@Last@Last@Reap[Plot[f[x] - y[x], {x, 0.2, 2000}, 
           EvaluationMonitor :> Sow[{x, f[x] - y[x]}]]], 2, 1], #[[2, 2]] #[[1, 2]] <= 0 &]];
Plot[{f[x], y[x]}, {x, 0.2, 10}, PlotRange -> Full, AxesOrigin -> {0, 0}, 
  Epilog -> {Red, PointSize@.02, Point@{#, y@#} &@x0}]

Mathematica graphics

So the coordinates of the point are:

{#, y@#} &@x0
{0.44, 0.29}
$\endgroup$
2
$\begingroup$

I might sound terribly pedantic here, but the answer is simply: Not at all.

The problem is that you have a finite set of data points, none of which has a y-value of 0.29. So there is no 'intersection' between a constant line and a number of points.

The other two answers above gave you a solution on how to find the intersection between the horizontal line and a suitably interpolated data set - in both cases linear interpolation has been assumed. That works, of course, but is the answer to your question only under very restricted circumstances (in case you wonder ListLinePlot has the option InterpolationOrder).

So if this is a real-world problem, you would have to specify what sort of function is used to either interpolate or fit your data set and then use FindRoot or 'NSolve' to obtain a numerical approximation.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.