A4 Python for engineers · Practice
Problem set 8: arrays and plots
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
For 10 cycles of sampled at 100 points per cycle (A = 1, f = 50 Hz, dc = 0.5 V), set vpp to the peak-to-peak value, vrms to the RMS of v, and vac to the RMS of v with its mean removed.
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 noisy readings v sampled every millisecond. Set n_high to how many exceed th = 2.5 V, first_high to the time in ms of the first one (or None), and longest to the longest run of consecutive high samples.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For every pair of E12 resistors from 1 kΩ to 8.2 kΩ in the starter (top R1, bottom R2), compute the loaded divider output into a load RL = 1000 Ω as a 2D array vout (rows for R2, columns for R1). Set n_ok to how many pairs give an output within 1% of Vs / 3.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A second-order low-pass has . Make a two-subplot Bode plot (gain in dB on top, phase in degrees below, log frequency axes) from to , with f0 = 1000 Hz and Q = 0.7. Set peak_db to the largest gain in dB on your frequency grid.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
X holds 24 hourly readings for each of 7 days (shape 7 × 24, made in the starter). Set daily_mean (one per day), hourly_mean (one per hour, averaged over the days), and worst_day, worst_hour where the single largest reading is.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Full-wave rectify a mains sine of amplitude A = 170 V at f = 50 Hz (take ), sampled at 200 points per cycle over 5 cycles. Set vdc to the average of the rectified wave and ratio to vdc / A.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Make a n × n grid of points with x and y from −1 to 1 using np.meshgrid, and set inside to the fraction of grid points with .
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