These shared examples illustrate the format of questions, reference materials, and answers; they are not predicted exam questions. Follow each course's exam guidance for the actual scope and provided materials.
Problem solving
Example 1
Provided references
Let the water volume be [L] and the inflow and outflow per minute be [L/min]. Then .
Problem
A tank contains 4 L of water, with 3 L flowing in and 1 L flowing out per minute. These rates remain constant for 2 minutes, and the tank does not overflow. Set the starting time to t=0.
Find an expression for and calculate the water volume after 2 minutes. Show how you apply the initial value, and include units.
Example answer
Since , . At , , so [L]. Therefore, .
Example 2
Provided references
.
Problem
Of 20 equipment measurement records, 4 are actual faults and 16 are normal. The decisions of two models are shown below. Each number is the count of corresponding records.
Actual status
Model decision
A
B
Fault
Fault
0
3
Fault
Normal
4
1
Normal
Fault
0
5
Normal
Normal
16
11
Calculate the accuracy of both models and show your calculations.
Missing a fault by classifying it as normal costs 10 per case; raising a false alarm by classifying a normal case as faulty costs 1 per case. Calculate each model's total error cost, and state which model has the lower cost and why you chose it.
Example answer
A: , B: .
A's cost is , and B's is . Choose B based on cost. B has more false alarms but reduces costly missed faults.
Example 3
Provided references
The average rate of change between two times is .
Problem
Voltage measurements over time are shown below. Represent values between measurement times by connecting each pair of points with a straight line.
Time [s]
Voltage [V]
0
0
1
2
2
2
3
2
Draw a graph connecting the four measurement points, with time [s] on the horizontal axis and voltage [V] on the vertical axis. Label the axes and units, and mark the measurement points.
Calculate the average rate of change in voltage from 0 seconds to 1 second, and include units.
Example answer
It rises linearly from 0 V at 0 seconds to 2 V at 1 second, then remains constant at 2 V until 3 seconds.
.
MATLAB
Example 1
Provided references
mean(v): If v is a row vector, returns the arithmetic mean of all its elements as a scalar.
Problem
The MATLAB code below selects the first and third elements of x and computes their mean.
x = [2 4 6];
picked = x([1 3]);
a = mean(picked);
Write the values and array sizes of picked and a. Express each size as rows × columns.
Example answer
picked=[2 6], with size 1×2. , with size 1×1.
Example 2
Provided references
numel(v): Returns the number of elements in array v.
Problem
The MATLAB code below adds only the positive values in x.
x = [1 -1 2];
total = 0;
for k = 1:numel(x)
if x(k) > 0
total = total + ____;
end
end
Fill in the blank to add only positive values.
Tabulate total by k immediately after each iteration.
Example answer
The blank is x(k).
At k=2, x(2)=-1, so the if body is skipped and total remains 1.
k
x(k)
total
1
1
1
2
-1
1
3
2
3
Example 3
Provided references
a:b: Creates a row vector from a to b in increments of 1.
plot(x,y): Uses values at matching positions in x and y as coordinates, then connects the points in order with straight lines.
Problem
In the MATLAB code below, t represents time [s] and y represents voltage [V].
t = 0:2;
y = 2*t;
plot(t,y);
Write the values of t and y, and sketch the graph drawn by plot. Label the axes and units, and mark the three points.
Example answer
t=[0 1 2], y=[0 2 4]. Connecting the three points gives a straight line through the origin.
Python
Example 1
Provided references
Multiplying or adding a scalar to a NumPy array applies the operation to each element.
v[mask]: Selects elements of v in order at positions where the Boolean array mask of the same length is True.
Problem
The Python code below selects elements of y corresponding to values in array x that are at least 2. np refers to NumPy.
x = np.array([1, 2, 3])
y = 2*x + 1
mask = x >= 2
selected = y[mask]
Write the values of y, mask, and selected in execution order. Also explain why the position where x=2 is selected.
Example answer
y=[3,5,7], mask=[False,True,True], selected=[5,7]. >= includes the boundary value 2, so the second position is also selected.
Example 2
Provided references
d.get(key,default): Returns the stored value if key is in dictionary d; otherwise, returns default. It does not modify the dictionary itself.
Problem
The Python code below counts how often each character appears in a list.
counts = {}
for name in ["A", "B", "A"]:
counts[name] = counts.get(name, 0) + ____
Fill in the blank so that the count increases by 1 each time a character is read. Write the value of counts after the loop ends.
Example answer
The blank is 1. After the first A, the dictionary is {"A":1}; after B, {"A":1,"B":1}; and after the final A, {"A":2,"B":1}. The final value is {"A":2,"B":1}; the key order may differ.
Example 3
Provided references
sum(v) returns the sum of the elements, and len(v) returns the number of elements. For an empty list [], both are 0.
Problem
The Python function below returns the mean of the input list.
def average(values):
return sum(values) / len(values)
result = average([2, 4])
Write the value of result and show the calculation.
Explain why average([]) cannot return a mean, including the calculation it attempts.
Example answer
result=3.0. The input list's sum, 6, is divided by its 2 elements, giving .
For an empty list, computing causes division by 0. It does not return a mean of 0.
Example 4
Provided references
x.mean(dim=k): Reduces the selected axis by averaging and removes it from the result. With dim=0, it averages elements in each column, leaving one value per column; with dim=1, it averages elements in each row, leaving one value per row.
Problem
These are temperatures [°C] measured by two sensors at two times. Each row of x represents a time point, and each column represents a sensor. torch refers to PyTorch.
x = torch.tensor([[1., 3.],
[5., 7.]])
m = x.mean(dim=0)
Write the value and shape of m. Explain which measurements from which sensor are averaged in each element of m.
Example answer
m=[3.,5.], with shape (2,). The first element averages sensor 1's values at two times, ; the second averages sensor 2's, . Reducing the time axis leaves two means, one per sensor.