A4 · Problem set 6
Problem set 6: program structure
These labs use lessons 19 to 25: the standard library, classes, state machines, recursion and searching, running time, and sorting. They're closer to real tools: an impedance sweep, a component model, a solver, a Monte Carlo check.
Check
For a series RLC with R = 10 Ω, L = 1 mH and C = 1 µF, set Z to a list of complex impedances at the frequencies in fs, and fmin to the frequency in fs where is smallest.
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 Capacitor with attributes C (farads) and esr (ohms) and a method impedance(f) returning the complex . Set z = Capacitor(C * 1e-6, esr).impedance(f) and mag = abs(z).
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 has with fc = 1000 Hz. Use bisection between fc and 1000 * fc to set f to the frequency where = g = 0.5, to within 1e-9 relative.
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 DAC adds vref/2 for its first bit, vref/4 for the second, and so on. Write a recursive dac(bits, vref) for a list of 0s and 1s (most significant first), and set v = dac(code, vref) for the starter's code.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two resistors of 10 kΩ ±t% each form a 50% divider. With random.seed(1), draw 10,000 pairs (each resistor 10e3 * random.uniform(1 - t/100, 1 + t/100), top then bottom) and set frac to the fraction of dividers whose ratio is within ±spec% of 0.5.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using bisect.bisect_left on the sorted E24 list in the starter, set best to the E24 value nearest target = 3600.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Set unique to how many distinct readings the list holds and repeats to how many readings are repeats of an earlier one, in one pass with a set.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Two loggers recorded (time, value) pairs, each list sorted by time. Without calling sort or sorted, merge them in one pass into a single list sorted by time, taking logger A's entry first when times tie. Then set merged to that list, and q to the nearest-rank pth percentile (50) of all the values (you may sort the values for that).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Have paper and a calculator ready. Work each problem out by hand, then enter the answer. Your first try on each one counts toward your score.
Practice
Keep practicing
8 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.