Graph of points with unknown function - How to curve fit it?

So I'm in my physics lab trying to graph these points:

data = {{-0.02, 1.9}, {-0.08, 1.8}, {-0.11, 1.7}, {-0.16, 1.6},{-0.22, 1.45}, {-0.28, 1.4}, {-0.35, 1.35}, {-0.40, 1.35}, {-0.45, 1.4}, {0.02, 1.9}, {0.08, 1.82}, {0.11, 1.7}, {0.16, 1.63}, {0.22, 1.45}, {0.28, 1.4}, {0.35, 1.3}, {0.40, 1.35}, {0.45, 1.4}}


And I was able to plot the points as:

plot = ListPlot[data]


But I can't make its fitting curve where it should look like this scheme:

• Does your drawing of a curve have a known functional form? For example, is it symmetric?
– JimB
Sep 30, 2021 at 20:46
• The result of your code seems quite reasonable. Perhaps, your sketch is incorrect. Sep 30, 2021 at 20:53
• @JimB It should be symmetric according to my lab instructor. Oct 1, 2021 at 12:30
• @bbgodfrey I've been instructed to draw a fitting curve in each side as the scheme, and not to stop in the points representation of the data. Oct 1, 2021 at 12:32

Clear["Global'*"];

\$Version

(* "12.3.1 for Mac OS X x86 (64-bit) (June 19, 2021)" *)

data = {{-0.02, 1.9}, {-0.08, 1.8}, {-0.11, 1.7}, {-0.16, 1.6}, {-0.22,
1.45}, {-0.28, 1.4}, {-0.35, 1.35}, {-0.40, 1.35}, {-0.45, 1.4}, {0.02,
1.9}, {0.08, 1.82}, {0.11, 1.7}, {0.16, 1.63}, {0.22, 1.45}, {0.28,
1.4}, {0.35, 1.3}, {0.40, 1.35}, {0.45, 1.4}};


To find an approximation use FindFormula

f = FindFormula[data, SpecificityGoal -> 3]

(* 1.59017 + 0.276431 Cos[9. #1] & *)


Or use Interpolation

f2 = Interpolation[data];

{{xmin, xmax}, {ymin, ymax}} = MinMax /@ Transpose[data];

Legended[
Plot[{f[x], f2[x]}, {x, xmin, xmax},
PlotRange -> {0.99 ymin, 1.01 ymax},
PlotStyle -> {Automatic, Dashed},
Frame -> True,
Epilog -> {Red, AbsolutePointSize[4],
Point[data]},
PlotLegends -> Placed[
{"approximation", "interpolation"},
{0.8, 0.85}]],
Placed[PointLegend[{Red}, {"data"}], {0.77, 0.7}]]


• Wow! That's so amazing! Thanks.Can't we separate the curve into two as the scheme though? Oct 1, 2021 at 12:08
• If there is some model for the data based on theory, then provide that model and use a fitting technique (e.g., NonlinearModelFit) Oct 1, 2021 at 14:22
• The equation is the periodic time of simple pendulum: T=2*Pi*sqrt[L/g], where L (length) is in x and T (Periodic time) is in y and the rest are constants. Even though length (L) is always positive, I did the experiment twice, one on every side, then my instructor asked me to merge them in one graph so I write the x part of the second try as negative values. Oct 2, 2021 at 17:14
• I cannot make any sense of your data given the model that you provided. Oct 2, 2021 at 17:58
Clear[x]
{a, b} = Fit[#, {1, x, x^2, x^3}, x] & /@ TakeDrop[data, 9];
c = Solve[a == b, x][[2, 1, 2]];
Plot[Piecewise[{{a, x < c}, {b, x > c}}], {x, -0.45, 0.45}, Axes -> None,
Epilog -> {PointSize[0.015], Point /@ data}, Frame -> True]