Finding the maximum on an interval and find root
I have a function f that is the truncation of the fourier transform of a sequence (i.e. f = sum( cos(a*x) for a in sequence), where sequence has 10,000 terms). I want to find the absolute maximum on an interval.
The documentation suggest getting the maximum of the plot, which works. I would like to know where this maximum occurs, though. As the maximum is 3272.9689885743473, f - 3200 should have a root, but find_root doesn't find a root. I guess this is technically a bug, but not very surprising given the definition of f.
My main question is, how do I find out where this maximum occurs? I can squint at the plot, but this isn't accurate enough.
sequence = [3, 4, 6, 9, 10, 17, 18, 25, 30, 32, 37, 44, 45, 52, 59, 60, 71, 72, 73, 86, 87, 94, 99, 106, 107, 114, 121, 122, 134, 135, 142, 149, 156, 161, 163, 168, 175, 176, 183, 190, 197, 204, 211, 218, 225, 226, 237, 238, 245, 252, 253, 265, 266, 273, 280, 287, 288, 300, 301, 314, 315, 322, 327, 334, 335, 342, 349, 350, 362, 363, 370, 377, 384, 391, 396, 403, 404, 411, 418, 419, 431, 432, 439, 446, 453, 454, 465, 466, 473, 480, 481, 493, 494, 501, 508, 515, 516, 528, 529, 542, 543, 550, 555, 562, 563, 570, 577, 584, 591, 598, 605, 612, 619, 620, 631, 632, 639, 646, 647, 659, 660, 667, 674, 681, 682, 694, 695, 708, 709, 721, 722, 729, 736, 743, 744, 756, 757, 764, 771, 772, 784, 785, 798, 805, 812, 813, 825, 826, 833, 840, 841, 848, 853, 860, 867, 874, 875, 887, 888, 895, 902, 903, 910, 915, 922, 923, 930, 937, 944, 949, 956, 957, 964, 971, 972, 984, 985, 992, 999, 1006, 1013, 1018, 1026, 1033, 1040, 1041, 1053, 1054, 1061, 1068, 1069, 1080, 1081, 1082, 1095, 1102, 1103, 1115, 1116, 1123, 1130, 1137, 1138, 1150, 1157, 1158, 1165, 1172, 1177, 1184, 1185, 1192, 1199, 1200, 1212, 1213, 1220, 1227, 1234, 1235, 1246, 1247, 1254, 1261, 1262, 1269, 1274, 1281, 1282, 1289, 1296, 1297, 1309, 1310, 1323, 1324, 1331, 1336, 1343, 1344, 1351, 1358, 1365, 1372, 1379, 1386, 1393, 1400, 1401, 1412, 1413, 1420, 1427, 1428, 1440, 1441, 1448, 1455, 1462, 1463, 1475, 1482, 1489, 1490, 1502, 1503, 1510, 1517, 1524, 1525, 1537, 1538, 1551, 1552, 1559, 1566, 1571, 1578, 1579, 1586, 1593, 1594, 1606, 1607, 1614, 1621, 1628, 1629, 1640, 1641, 1648, 1655, 1656, 1668, 1669, 1676, 1683, 1690, 1691, 1703, 1704, 1717, 1718, 1725, 1730, 1737, 1738, 1745, 1752, 1759, 1766, 1773, 1780, 1787, 1794, 1795, 1806, 1807, 1814, 1821, 1822, 1834, 1835, 1842, 1849, 1856, 1857, 1869, 1870, 1883, 1884, 1896, 1897, 1904, 1911, 1918, 1919, 1931, 1932, 1939, 1946, 1953, 1960, 1965, 1973, 1980, 1987, 1988, 2000, 2001, 2008, 2015, 2022, 2023, 2035, 2042, 2049, 2050, 2062, 2063, 2070, 2077, 2078, 2085, 2090, 2097, 2104, 2111, 2112, 2119, 2124, 2131, 2132, 2139, 2146 ...