A4 Python for engineers · Practice
Final exam
Problems dealt one at a time, with new numbers every time. The kinds you miss come back more often, and you can keep going as long as you like.
Check
An n-th order Butterworth low-pass has . For n = 2 and fc = 300 Hz, on 500 log-spaced frequencies from to , set gdb to the gain in dB and slope to the roll-off in dB per decade measured between and (the last two decades' endpoints).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Read the CSV in the starter (a comment line, a header, then t in ms and v in mV), convert to seconds and volts, and set t, v, then vpp (peak to peak, V) and f_est: the frequency estimated from the average spacing of rising zero crossings of v - v.mean().
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from to with RK4 in n = 50 steps and with 2 * n steps (tau = 1). Set v1, v2 to the two final values and est to the estimated error of v2, .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A divider of 10 kΩ over 10 kΩ feeds an RC low-pass of 10 kΩ and 100 nF; the output is at the capacitor. Model every resistor as uniform ±tR% and the capacitor as uniform ±tC%. With default_rng(3), draw 100,000 boards (top, bottom, filter R, then C). The DC gain is the divider ratio, and the corner is where is the divider's Thevenin resistance. Set gain, fc (arrays) and yld: the fraction with gain within ±2% of 0.5 and corner within ±5% of nominal.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter makes a record of two tones in noise, sampled at 8 kHz for 8000 samples. Using a Hann window (np.hanning) before np.fft.rfft, set peaks to the sorted frequencies of the two largest local maxima of the spectrum's magnitude (ignoring DC).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write a class Part with name, value and tol (a fraction) and a method bounds(). From the starter's list of tuples, make a list of Part objects and set widest to the name of the part with the largest absolute tolerance band (value * tol), and total to a dictionary from the first letter of each name to the sum of the nominal values with that letter.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor charges as with = 2 ms and V = 3.3 V. Find the time when it reaches th = 0.5 of V three ways: t_exact from the formula, t_bisect by bisection on [0, 20 ms] to 1e-12 s, and t_samples as the first sample time at or above the threshold on a 0.01 ms grid. All in seconds.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Compare three integrals of from 0 to 3 on n = 30 slices: left (rectangles using the left end of each slice), trap (trapezoid) and simp (Simpson). Set exact from the formula , and best to the name, "left", "trap" or "simp", of the most accurate.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
A kind of problem counts as solid once you've got it right on the first try twice in a row. Back to the lesson · Practice every topic in A4