A common task is a graphical representation of a scalar function over a rectangle:
For this, first we have to generate a grid on the rectangle . This is done using the command meshgrid :
n = ... # number of discretization points along the x-axis
m = ... # number of discretization points along the x-axis
X,Y = meshgrid(linspace(a,b,n), linspace(c,d,m))
X and Y are arrays with an (n,m) shape such that X[i,j] and Y[i,j] contain the coordinates of the grid point , as shown in Figure 6.6:
Figure 6.6: A rectangle discretized by meshgrid.
A rectangle discretized by meshgrid will be used in the next section to visualize the behavior of an iteration, while we will use it here to plot the level curves of a function. This is done by the command contour.
As an example, we choose Rosenbrock's banana function:
It is used to challenge optimization methods, see [27]. The&...