Numerical differentiation: Difference formulas for the first derivative
Derivative via a 5-point difference method (programming assignment)
In this assignment we look again at how we can approximate the derivative of a discretisation of the sine function on the interval via a difference formula. We divide the interval into 25 equidistant points. This assignment is specified in the Python language, but other programming languages like Matlab and R provide similar built-in functions. So, in other programming language you can also do this assignment.
Use the numpy
and matplotlib
package to calculate the derivatives in the points on the interval via the central 5-point difference formula and to make a scatterplot of the function and its derivatives in one diagram.
- Do it via cross-correlation the first time (and use the 'same' option to get an array of the same length as the number of points.
- Do it the second time using the numpy function
roll
which allows you to rotate an array. - Repeat part (1) with equidistant points, with equidistant points, and with equidistant points. Do the approximations improve as you take more points on the interval?
Unlock full access