Probably a fairly easy one; but I'm drawing a blank I would like to find the maximum of an interpolated data set. I've tried using
maxCurrent =
FindMaximum[
Interpolation[dataNi59s, InterpolationOrder -> 2], {y,
dataNi59s[[1]]}]
Just for clarification - I would like to return the maximum value of the interpolation of the data, rather than just the largest value in the data set.
Edit 1: A lot of the answers have (I presume correctly) outputted the answer as '{28.9179, {x -> 177.957}}', however the intended result is to output ONLY the largest value of y that lies on the blue interpolated line - by eye this looks to be about 23.9uA. (The x-co-ordinate is at about 400, and if anyone knows how to return that separately that would also be very helpful)
I've included this image to help clarify - I would like to return the y co-ordinate of the point labelled with a red arrow
Edit 2:
For the record - following Aardvark's advice that finding the peak of the ListLinePlot interpolation line was physically not meaningful, i decided to just output the highest current value of one of the data points. Aardvark's answer does show how to do this, but technically it outputs all points that share that maximum and the x and y co-ordinate, whereas i just wanted the y-co-ordinate once. So for posterity, here is the code I used to do that, based on Aardvark's answer
maxCurrent = MaximalBy[dataNi59s, Last][[1, 2]]
This returns (for my data) just: 23.4
, which is the new intended result.
For any future reader, if you'd like to know how to find the maximum of the ListLinePlot as I clarified in Edit 1 with the red arrow on the graph, then it can be found in update 2 of Aardvark's answer.
Data:
dataNi59s = {{26, 8.07}, {28, 9.12}, {36, 11.9}, {40, 13.4}, {66,
17.5}, {69, 17.9}, {163, 18.9}, {165, 21.4}, {191, 21.3}, {200,
21.6}, {214, 21.5}, {227, 21.2}, {260, 20.9}, {342, 20.8}, {362,
23.4}, {497, 23.4}, {510, 23.3}, {535, 22.9}, {566, 22.4}, {577,
22.2}, {596, 21.9}, {607, 21.7}, {671, 21.0}, {682, 20.7}, {689,
20.5}, {700, 20.9}, {704, 20.8}, {799, 19.6}, {809, 19.5}, {823,
19.6}, {831, 19.5}, {841, 19.3}, {852, 19.3}, {875, 19.1}, {881,
19.1}, {901, 19.0}, {911, 19.0}, {928, 19.0}, {955, 18.8}, {973,
18.7}, {978, 18.6}, {1048, 18.5}, {1067, 18.4}, {1090,
18.2}, {1111, 18.1}, {1126, 18.0}, {1134, 17.9}, {1196,
17.7}, {1200, 17.6}, {1215, 17.6}, {1227, 17.5}, {1270,
17.4}, {1367, 16.6}, {1377, 16.6}, {1381, 16.5}, {1494,
16.3}, {1534, 16.3}, {1584, 16.0}, {1686, 15.4}, {1700,
15.3}, {1707, 15.3}, {1805, 14.5}, {1869, 21.6}, {1878,
21.3}, {1905, 21.1}, {1968, 21.0}, {1980, 21.0}, {2010,
20.9}, {2025, 20.8}, {2063, 20.5}, {2070, 20.5} , {2109,
20.1}, {2146, 19.8}, {2232, 19.3}, {2249, 19.1}, {2280,
18.8}, {2347, 18.1}, {2370, 17.9}, {2394, 17.8}, {2400,
17.6}, {2416, 17.5}, {2430, 17.4}, {2452, 17.2}, {2462,
17.1}, {2488, 17.0}, {2508, 16.8}, {2528, 16.5}, {2599,
15.7}, {2604, 15.2}, {2612, 15.0}, {2637, 14.7}, {2651,
14.6}, {2660, 14.5}, {2760, 13.6}, {2769, 13.6}, {2805,
13.2}, {2844, 12.9}, {2880, 12.6}, {2904, 12.4}, {3040,
12.4}, {3081, 12.1}, {3189, 11.6}, {3221, 11.5}, {3314,
10.7}, {3602, 12.5}, {3610, 12.1}, {3624, 12.0}, {3635,
12.0}, {3640, 11.7}, {3735, 11.1}, {3765, 11.1}, {3797,
11.0}, {4066, 7.71}, {4120, 5.91}, {4123, 5.78}, {4129,
5.61}, {4169, 4.77}, {4174, 4.69}, {4183, 4.56}, {4188,
4.45}, {4194, 4.40}, {4200, 4.36}, {4221, 4.13}, {4345,
4.47}, {4360, 4.39}, {4492, 3.83}, {4550, 3.99}, {4567,
3.94}, {4574, 3.93}, {4580, 3.92}, {4600, 3.95}, {4652,
3.79}, {4679, 3.56}, {4794, 3.49}, {4842, 3.59}, {5049,
4.37}, {5094, 4.47}, {5124, 3.94}, {5167, 3.11}, {5172,
3.07}, {5210, 2.92}, {5278, 2.78}, {5314, 2.76}, {5327,
2.75}, {5442, 2.81}, {5479, 2.79}, {5565, 2.72}, {5580,
2.71}, {5768, 2.26}, {5929, 1.03}, {5941, 1.03}, {5948,
1.03}, {6000, 1.01}, {6058, 0.992}, {6059, 1.14}, {6210,
1.04}, {6328, 0.977}, {6330, 0.998}, {6333, 1.01}, {6351,
1.01}, {6420, 1.00}, {6434, 0.964}, {6441, 1.02}, {6611,
1.01}, {6661, 1.00}, {6696, 1.03}, {6908, 0.968}};
Graph Code:
{Ni59s[1], Ni59s[2]} = SplitBy[dataNi59s, #[[1]] < 1850 &];
avgCurrent =
Integrate[
Interpolation[dataNi59s, InterpolationOrder -> 2][x], {x,
dataNi59s[[1, 1]], dataNi59s[[-1, 1]]}]/(Subtract @@
dataNi59s[[{-1, 1}, 1]]);
maxCurrent =
FindMaximum[
Interpolation[dataNi59s, InterpolationOrder -> 2], {y,
dataNi59s[[1]]}]
noPoints = Length[dataNi59s];
lifeTime = dataNi59s[[-1, 1]];
ListLinePlot[{Ni59s[1], Ni59s[2]}, PlotRange -> {{0, 7000}, {0, 25}},
PlotStyle -> {Directive[RGBColor[0., 0.75, 0.85],
AbsoluteThickness[2.5]]}, PlotTheme -> "Detailed",
Epilog -> {{Dashed, Line[{{1805, 14.5`}, {1869, 21.6`}}]}, {Red,
AbsolutePointSize[4], Point[dataNi59s]}, {GrayLevel[.5],
InfiniteLine[{{0, 1}, {1, 1}}]},
Inset[Framed[
Grid[{{"Average Current: ", avgCurrent,
" \[Mu]A"}, {"Cathode Lifetime: ", lifeTime,
"minutes"}, {"No. of Data Points: ", noPoints}}],
Background -> White, RoundingRadius -> 5], Scaled[{.85, .9}]]},
PlotLabel ->
"Comparison of Current Yields from Nickel Cathode 59 (Interpolated) \
(Anomolous Points Removed)",
PlotLegends ->
Placed[LineLegend[{"Cathode 59 - Nickel"},
LegendFunction -> "Panel"], {0.85, 0.5}],
LabelStyle -> {Black, Bold}, Frame -> {{True, False}, {True, False}},
FrameLabel -> {"Cathode Runtime (minutes)", "Current (\[Mu]A)"},
ImageSize -> {850, 550}, InterpolationOrder -> 2]
Graph Code (following this question's answers):
{Ni59s[1], Ni59s[2]} = SplitBy[dataNi59s, #[[1]] < 1850 &];
avgCurrent =
Integrate[
Interpolation[dataNi59s, InterpolationOrder -> 2][x], {x,
dataNi59s[[1, 1]], dataNi59s[[-1, 1]]}]/(Subtract @@
dataNi59s[[{-1, 1}, 1]]);
maxCurrent = MaximalBy[dataNi59s, Last][[1, 2]];
noPoints = Length[dataNi59s];
lifeTime = dataNi59s[[-1, 1]];
ListLinePlot[{Ni59s[1], Ni59s[2]}, PlotRange -> {{0, 7000}, {0, 25}},
PlotStyle -> {Directive[RGBColor[0., 0.75, 0.85],
AbsoluteThickness[2.5]]}, PlotTheme -> "Detailed",
Epilog -> {{Dashed, Line[{{1805, 14.5`}, {1869, 21.6`}}]}, {Red,
AbsolutePointSize[4], Point[dataNi59s]}, {GrayLevel[.5],
InfiniteLine[{{0, 1}, {1, 1}}]},
Inset[Framed[
Grid[{{"Average Current: ", avgCurrent,
" \[Mu]A"}, {"Maximum Current: ", maxCurrent,
" \[Mu]A"}, {"Cathode Lifetime: ", lifeTime,
"minutes"}, {"No. of Data Points: ", noPoints}}],
Background -> White, RoundingRadius -> 5], Scaled[{.85, .9}]]},
PlotLabel ->
"Comparison of Current Yields from Nickel Cathode 59 (Interpolated) \
(Anomolous Points Removed)",
PlotLegends ->
Placed[LineLegend[{"Cathode 59 - Nickel"},
LegendFunction -> "Panel"], {0.85, 0.5}],
LabelStyle -> {Black, Bold}, Frame -> {{True, False}, {True, False}},
FrameLabel -> {"Cathode Runtime (minutes)", "Current (\[Mu]A)"},
ImageSize -> {850, 550}, InterpolationOrder -> 2]