A delivery drone hovering at one height is told to climb to a new height. Its altitude controller does not stop exactly there at once: a lively controller climbs fast, shoots past the new height, and settles back. Engineers describe that with the percent overshoot: how far the response went beyond its final value, as a percentage of the size of the step.
You get the altitude log samples (metres, one sample per tenth of a second, starting at the moment of the command) and the final altitude the drone settles at. The step goes up: final is greater than samples[0]. Then
overshoot = 100 * (peak - final) / (final - samples[0])
where peak is the highest sample. If the response never goes above final, the overshoot is 0.
Write percent_overshoot(samples, final) that returns the overshoot as a float. Press Run with plot(samples) to see the response.
Examples
Input: samples = [0, 4, 8, 11, 12.5, 11, 9.5, 10.2, 10], final = 10
Output: 25.0
Explanation: the drone went 2.5 m past 10 m on a 10 m step: 25 %.
Input: samples = [2, 5, 7, 7.8, 8], final = 8
Output: 0.0
Explanation: it never went above 8 m.
Input: samples = [30, 33, 36, 35], final = 34
Output: 50.0
Explanation: a 4 m step from 30 m; the peak of 36 m is 2 m past the final value.
Constraints
- answers are compared with a tolerance of
1e-6; do not round
Goals
- Read a step response: where it starts, where it ends and how high it peaks
- Express overshoot as a percentage of the size of the step
- Report zero when a response never goes past its final value