Skip main navigation

£199.99 £139.99 for one year of Unlimited learning. Offer ends on 28 February 2023 at 23:59 (UTC). T&Cs apply

Find out more

Hands-on: Finite difference

Calculate finite difference using vectorised operations.
© CSC - IT Center for Science Ltd.

In this exercise we study vectorization, which is crucial for obtaining good performance with NumPy.

Source code for this exercise is located in numpy/finite-difference/

Derivatives can be calculated numerically with the finite-difference method

[f'(x_i) = frac{f(x_i + Delta x)- f(x_i – Delta x)}{2 Delta x}]

Construct 1D Numpy array containing the values of xi in the interval [0,π/2]
with spacing Δx=0.1. Evaluate numerically the derivative of sin in this
interval (excluding the end points) using the above formula. Try to avoid
for loops. Compare the result to function cos in the same interval.

© CSC - IT Center for Science Ltd.
This article is from the free online

Python in High Performance Computing

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education