1
$\begingroup$

I have the following table

data = Table[Sin[i], {i, 0, 10, 0.1}] // N

And I plotted the data as follows,

Now I want to know the value of each maximum with high accuracy. It can see that for example the first maximum is around 1.0. However, I want it in terms of an accurate number. Can I do it using interpolation? If yes, how can I know what should be the accurate starting point?

I appreciate it if you could help me.

enter image description here

$\endgroup$
1
  • $\begingroup$ From data with machine precision you can not get an exact answer. Exact means infinite precision. For this you need an analytic procedure, like setting the derivative to zero. $\endgroup$ Sep 27, 2023 at 13:00

2 Answers 2

2
$\begingroup$

Find the peaks

peaks = FindPeaks[data]

{{17, 0.999574}, {80, 0.998941}}

But the "accurate number" should be 1

FunctionRange[Sin[x], x, y]

-1 <= y <= 1

Hence

Round[peaks, 1]

{{17, 1}, {80, 1}}

To find the corresponding x-values:

x /. Solve[Sin[x] == 1, x] /. C[1] :> {0, 1} // Flatten

{Pi/2, (5*Pi)/2}

ListLinePlot[data, 
 Epilog -> {Red, PointSize[Large], Point @ FindPeaks[data]}]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks for your help! $\endgroup$
    – Lohrasb
    Sep 27, 2023 at 10:45
  • $\begingroup$ You're most welcome $\endgroup$
    – eldo
    Sep 27, 2023 at 10:46
0
$\begingroup$

I suggest a graphical solution. The procedure can be used universally, not just specifically for the data given here. To get a more accurate solution I increased the resolution by 10.

data = Table[Sin[i], {i, 0, 10, 0.01}];
f = Interpolation@data;
p = Plot[f[x], {x, 0, 1000}, Mesh -> {{0}}, 
   MeshFunctions -> {f'[#] &}, MeshStyle -> {Red, PointSize@Medium}] //Quiet

enter image description here

 pts = Cases[p, Point[{x_, y_ /; y > 0}] :> {x/100, y}, \[Infinity]] //Sort

{{1.5808, 0.999999}, {7.86396, 0.999999}}

$\endgroup$

Your Answer

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

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