A4 Python for engineers · Practice
Problem set 9: complex numbers, equations and calculus in code
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 a series RLC with = 50 Ω, L = 10 mH and C = 0.1 µF, set f to 20,001 frequencies spaced evenly in from 10 Hz to 1 MHz (np.logspace), Z to the complex impedances there, f_min to the frequency where is smallest, and f0 to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An RC low-pass ( = 1 kΩ, = 10 nF) shifts the phase by . Write bisect(g, a, b) (60 halvings), use it to set f to the frequency where the phase is , and set f_formula to the exact answer from .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A sine with f = 200 Hz is sampled with step h. Write central(v, h) returning the central-difference derivative at the interior samples, (v[2:] - v[:-2]) / (2*h). Set err1 and err2 to the largest error against the exact derivative with 100 and 200 samples per cycle, and ratio = err1 / err2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A half-wave rectified sine is . Over one cycle, sampled at 10,001 points from 0 to , set rms_num to its RMS by the trapezoid rule (written with slices), rms_exact to , and avg to its average value by the same rule.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A series RLC circuit with = 100 Ω, = 10 mH and = 1 µF has the characteristic polynomial . Set roots to its roots with np.roots, kind to "under", "critical" or "over" (underdamped if the roots are complex), and zeta to .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor C = 10 µF charges from 0 toward V = 5 V through R = 100 Ω. Sample 10 time constants at 20,001 points. With and , set E_source to , E_cap to and E_res to , each by the trapezoid rule, then half = E_cap / E_source.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate from 0 to (exactly 2) with n = 8 intervals. Write trapezoid(f, a, b, n) and simpson(f, a, b, n) (n even), and set e_t and e_s to their errors, abs(result - 2).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An R-2R ladder DAC has nodes 1 to n (4 bits). Node 1 has a 2R resistor to ground; each node also has a 2R resistor driven by bit of the code (Vref = 5 V if the bit is 1, 0 V if it's 0); and an R resistor joins each node to the next. Using a stamped conductance matrix with each bit source as a Norton current, set vout to the voltage at node n for code = 1 (only its low n bits count) with R = 10 kΩ, and ideal to for those bits.
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