Exam format examples

English translation

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 V(t)V(t) [L] and the inflow and outflow per minute be qin,qoutq_{\mathrm{in}},q_{\mathrm{out}} [L/min]. Then dVdt=qin−qout\frac{dV}{dt}=q_{\mathrm{in}}-q_{\mathrm{out}}.

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.

  1. Find an expression for V(t)V(t) and calculate the water volume after 2 minutes. Show how you apply the initial value, and include units.
Example answer
  1. Since dVdt=3−1=2L/min\frac{dV}{dt}=3-1=2\,\mathrm{L/min}, V(t)=2t+CV(t)=2t+C. At V(0)=4V(0)=4, C=4C=4, so V(t)=4+2tV(t)=4+2t [L]. Therefore, V(2)=4+2×2=8LV(2)=4+2\times2=8\,\mathrm L.

Example 2

Provided references

Accuracy=number of correctly classified recordstotal number of records\mathrm{Accuracy}=\frac{\text{number of correctly classified records}}{\text{total number of records}}.

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 statusModel decisionAB
FaultFault03
FaultNormal41
NormalFault05
NormalNormal1611
  1. Calculate the accuracy of both models and show your calculations.
  2. 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
  1. A: 0+1620=0.8\frac{0+16}{20}=0.8, B: 3+1120=0.7\frac{3+11}{20}=0.7.
  2. A's cost is 4×10+0×1=404\times10+0\times1=40, and B's is 1×10+5×1=151\times10+5\times1=15. 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 change in measured valuetime interval\frac{\text{change in measured value}}{\text{time interval}}.

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]
00
12
22
32
  1. 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.
  2. Calculate the average rate of change in voltage from 0 seconds to 1 second, and include units.
Example answer
  1. It rises linearly from 0 V at 0 seconds to 2 V at 1 second, then remains constant at 2 V until 3 seconds.
  2. 2−01−0=2V/s\frac{2-0}{1-0}=2\,\mathrm{V/s}.
Voltage measurements over time0123012Time [s]Voltage [V]

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);
  1. Write the values and array sizes of picked and a. Express each size as rows × columns.
Example answer
  1. picked=[2 6], with size 1×2. a=2+62=4a=\frac{2+6}{2}=4, 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
  1. Fill in the blank to add only positive values.
  2. Tabulate total by k immediately after each iteration.
Example answer
  1. The blank is x(k).
  2. At k=2, x(2)=-1, so the if body is skipped and total remains 1.
    kx(k)total
    111
    2-11
    323

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);
  1. 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
  1. t=[0 1 2], y=[0 2 4]. Connecting the three points gives a straight line through the origin.
MATLAB plot output01201234Time [s]Voltage [V]

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]
  1. Write the values of y, mask, and selected in execution order. Also explain why the position where x=2 is selected.
Example answer
  1. 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) + ____
  1. 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
  1. 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])
  1. Write the value of result and show the calculation.
  2. Explain why average([]) cannot return a mean, including the calculation it attempts.
Example answer
  1. result=3.0. The input list's sum, 6, is divided by its 2 elements, giving 2+42=3\frac{2+4}{2}=3.
  2. For an empty list, computing 00\frac{0}{0} 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)
  1. Write the value and shape of m. Explain which measurements from which sensor are averaged in each element of m.
Example answer
  1. m=[3.,5.], with shape (2,). The first element averages sensor 1's values at two times, 1+52=3\frac{1+5}{2}=3; the second averages sensor 2's, 3+72=5\frac{3+7}{2}=5. Reducing the time axis leaves two means, one per sensor.