How would I go about finding the equation of the solid black line exponential/logarithm graph?

The two data points are:




enter image description here

  • $\begingroup$ You need more cordinates from curves, then apply some fiiting: Fit or maybe NonlinearModelFit. $\endgroup$
    – Alx
    Aug 4 '19 at 23:31

From physical considerations I would expect the power to fall off quadratically with distance: $P=A/(x+d)^2$ with $A$ the amplitude and $d$ the offset. Expressing this power in dBm gives $p=a-(20/\ln10)\ln(x+d)$ with $a$ containing $A$ as well as the milliwatt scale that is used to define the dBm unit. We can fit this form with only two data points:

data = {{9, -14}, {20, -21}};
f = NonlinearModelFit[data, a - 20/Log[10] Log[x + d], {a, d}, x];
(*    {a -> 4.96838, d -> -0.119874}    *)

Plot[f[x], {x, 0, 30}, Epilog -> Point /@ data]

enter image description here


I used WebPlotDigitizer software to get points of black solid curve from your picture. Then we can use various functions from Mathematica to make fitting.

First I used

FindFormula[d, x, TargetFunctions -> {Times, Exp, Log, Plus}]

this gives

-6.91808 Log[-0.790681 + x]

Next we can try

FindFit[d, a Log[b + x], {{a, -6}, {b, -0.8}}, x]

I used here initial values from FindFormula, and the result is

{a -> -6.92557, b -> -0.787053}

The same values for a and b come from

NonlinearModelFit[d, a Log[b + x], {{a, -6}, {b, -0.8}}, x] // Normal

Finally we can plot all fitting together and compare with original data:

lp = ListPlot[d, Frame -> True, Axes -> False, PlotStyle -> Directive[Red, PointSize[0.01]]];
ffit = Plot[Evaluate[a Log[b + x] /. FindFit[d, a Log[b + x], {{a, -6}, {b, -0.8}}, x]], {x, d[[1, 1]], d[[-1, 1]]}, PlotRange -> All, Frame -> True, Axes -> False, PlotStyle -> Blue];
fform = Plot[Evaluate@FindFormula[d, x, TargetFunctions -> {Times, Exp, Log, Plus}], {x, d[[1, 1]], d[[-1, 1]]}, PlotRange -> All, Frame -> True, Axes -> False, PlotStyle -> Darker@Green];
nlm = Plot[Evaluate[NonlinearModelFit[d, a Log[b + x], {{a, -6}, {b, -0.8}}, 
 x] // Normal], {x, d[[1, 1]], d[[-1, 1]]}, PlotRange -> All, Frame -> True, Axes -> False, PlotStyle -> Brown];
Legended[Show[lp, ffit, fform, nlm, GridLines -> Automatic, FrameLabel -> {"Distance, (m)", "Power (dBm)"}, ImageSize -> Large, BaseStyle -> 16], Placed[SwatchLegend[{Red, Blue, Darker@Green, Brown}, {"data", "FindFit", "FindFormula", "NonlinearModelFit"}], {0.8, 0.8}]]

enter image description here

  • $\begingroup$ From physical considerations, the form a+b*Log[c+x] may be more appropriate for fitting. The coefficient b should be -20/Log[10] (see my solution) but you can leave it open for fitting. $\endgroup$
    – Roman
    Aug 5 '19 at 10:35

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