Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A trolley is at the positions 0, 3, 12, 27, 48 and 75 m at the times 0, 1, 2, 3, 4 and 5 s. Find its speed at each time with np.gradient, once with the default rule and once with edge_order=2. Which one is right at the two ends? (The positions follow .)
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. np.gradient(x, t) uses the central difference inside and a one-sided difference at the ends. With edge_order=2, the ends use three points. The exact speed is .
Check. The exact speeds are 0, 6, 12, 18, 24 and 30 m/s. The default rule gives [3 6 12 18 24 27]: the inner values are exact, but the two ends are wrong, 3 and 27. With edge_order=2, the result is [0 6 12 18 24 30], exact everywhere, because the positions are a parabola, and the end rule fits a parabola.
Answer: the default rule is wrong at the ends (3 and 27 m/s). edge_order=2 gives the exact speeds 0, 6, 12, 18, 24 and 30 m/s.
Log in to join the discussion.
Loading…