2
$\begingroup$

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: enter image description here

$\endgroup$
4
  • 1
    $\begingroup$ Does your drawing of a curve have a known functional form? For example, is it symmetric? $\endgroup$
    – JimB
    Sep 30, 2021 at 20:46
  • $\begingroup$ The result of your code seems quite reasonable. Perhaps, your sketch is incorrect. $\endgroup$
    – bbgodfrey
    Sep 30, 2021 at 20:53
  • $\begingroup$ @JimB It should be symmetric according to my lab instructor. $\endgroup$
    – Shahad
    Oct 1, 2021 at 12:30
  • $\begingroup$ @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. $\endgroup$
    – Shahad
    Oct 1, 2021 at 12:32

2 Answers 2

3
$\begingroup$
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}]]

enter image description here

$\endgroup$
4
  • $\begingroup$ Wow! That's so amazing! Thanks.Can't we separate the curve into two as the scheme though? $\endgroup$
    – Shahad
    Oct 1, 2021 at 12:08
  • $\begingroup$ If there is some model for the data based on theory, then provide that model and use a fitting technique (e.g., NonlinearModelFit) $\endgroup$
    – Bob Hanlon
    Oct 1, 2021 at 14:22
  • $\begingroup$ 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. $\endgroup$
    – Shahad
    Oct 2, 2021 at 17:14
  • $\begingroup$ I cannot make any sense of your data given the model that you provided. $\endgroup$
    – Bob Hanlon
    Oct 2, 2021 at 17:58
1
$\begingroup$
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]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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