Scalar/vector field visualisation
MATH40006_Mock_1
July 31, 2026
1 MATH40006 Mock Examination 1
Time allowed: 60 minutes
T otal marks: 50
Answer all three questions in this Jupyter notebook.
This paper is an original equal-difficulty training paper. It follows the latest regular assessment
structure (20 + 20 + 10 marks).
[ ]: import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
import pandas as pd
from time import perf_counter
from copy import copy
import pickle
import ast
sp.init_printing()
1.1 Question 1 (20 marks)
The scalar function is
v(x,y) = x^2/2 + sin(y), for -2 <= x <= 2 and -pi <= y <= pi.
The computational domain is shown below.
1
(a) Define x_values1 and y_values1 as one-dimensional NumPy arrays of 101 equally spaced
points on the stated intervals. [2]
(b) Use meshgrid to define 101 by 101 arrays x1 and y1. [2]
(c) Use imshow, with correct origin and extent, to visualise v on the rectangle. [3]
(d) Create a contour plot of v using x1 and y1. [2]
(e) Define lower-resolution arrays x_values2 and y_values2 containing 21 equally spaced points
on the same intervals. [2]
(f) Use meshgrid to define x2 and y2. [2]
(g) Since v_x=x and v_y=cos(y), use quiver to plot the vector field (v_y,-v_x) on the lower-
resolution grid. [2]
(h) Superimpose the vector field in blue on red contours of v. [2]
(i) Use plot_wireframe to draw z=v(x,y) from x1 and y1. [3]
[ ]: # YOUR CODE HERE
raise NotImplementedError()
Worked solution and marking guidance
MATH40006_Mock_1_Solutions
July 31, 2026
1 MATH40006 Mock Examination 1
Time allowed: 60 minutes
T otal marks: 50
Answer all three questions in this Jupyter notebook.
This paper is an original equal-difficulty training paper. It follows the latest regular assessment
structure (20 + 20 + 10 marks).
1.1 Complete worked solutions and marking guide
[1]: import numpy as np
import sympy as sp
import matplotlib.pyplot as plt
import pandas as pd
from time import perf_counter
from copy import copy
import pickle
import ast
sp.init_printing()
1.2 Question 1 (20 marks)
The scalar function is
v(x,y) = x^2/2 + sin(y), for -2 <= x <= 2 and -pi <= y <= pi.
The computational domain is shown below.
1
(a) Define x_values1 and y_values1 as one-dimensional NumPy arrays of 101 equally spaced
points on the stated intervals. [2]
(b) Use meshgrid to define 101 by 101 arrays x1 and y1. [2]
(c) Use imshow, with correct origin and extent, to visualise v on the rectangle. [3]
(d) Create a contour plot of v using x1 and y1. [2]
(e) Define lower-resolution arrays x_values2 and y_values2 containing 21 equally spaced points
on the same intervals. [2]
(f) Use meshgrid to define x2 and y2. [2]
(g) Since v_x=x and v_y=cos(y), use quiver to plot the vector field (v_y,-v_x) on the lower-
resolution grid. [2]
(h) Superimpose the vector field in blue on red contours of v. [2]
(i) Use plot_wireframe to draw z=v(x,y) from x1 and y1. [3]
[2]: x_values1 = np.linspace(-2, 2, 101)
y_values1 = np.linspace(-np.pi, np .pi, 101)
x1, y1 = np.meshgrid(x_values1, y_values1)
v1 = x1**2/2 + np.sin(y1)
plt.figure()
plt.imshow(v1, origin ='lower', extent =[-2,2,-np.pi,np.pi], aspect ='auto')
plt.title('v(x,y)')
plt.figure()
plt.contour(x1, y1, v1)
2
x_values2 = np.linspace(-2, 2, 21)
y_values2 = np.linspace(-np.pi, np .pi, 21)
x2, y2 = np.meshgrid(x_values2, y_values2)
plt.figure()
plt.quiver(x2, y2, np .cos(y2), -x2)
plt.figure()
plt.contour(x1, y1, v1, colors ='red')
plt.quiver(x2, y2, np .cos(y2), -x2, color ='blue')
fig = plt.figure()
ax = fig.add_subplot(111, projection ='3d')
ax.plot_wireframe(x1, y1, v1)
plt.show()
3
4
5
Marking points / verification. 2 marks for the two correct 1D arrays; 2 for meshgrid; 3 for
imshow including origin='lower' and the correct extent; 2 for contours; 2+2 for the coarse grid;
2 for the correct vector components; 2 for the coloured overlay; 3 for a valid 3D wireframe. All
generated arrays are 101x101 or 21x21 as required.