A4 Python for engineers · Practice
Problem set 12: longer labs
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
Find the RC low-pass filter's −3 dB frequency numerically: write the magnitude in dB as a function of f, and use bisection between 1 Hz and 10 MHz to find where it equals −3.0103 dB. Set f3. (Check it against .)
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An inductor current builds up as . Simulate it with Euler's method from 0 A, with a step of for 500 steps, store the currents in i (501 values), and set err to the largest difference from the exact .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A capacitor discharges through an unknown resistor. The arrays t (s) and v (V) are noisy readings, and C is known. Fit the time constant from against , then set R_fit to the resistance.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For a series RLC with R = 1000 Ω, C = 10 nF and L = 47 mH, compute the voltage across the capacitor for a 1 V input as a complex transfer function over 400 log-spaced frequencies from 100 Hz to 1 MHz. Set f_peak to the frequency of the largest gain on that grid, gain_peak to the gain there, and Q to the theoretical .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A mains current is a fundamental at f1 = 50 Hz (amplitude 1 A) plus a harmonic h = 3 times higher with amplitude a = 0.2 A, sampled at 12 kHz for exactly 10 cycles of the fundamental. From the FFT, set I1 and Ih to the two amplitudes, thd to the total harmonic distortion , and irms to the RMS current computed from the samples.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter's netlist is a list of (name, a, b, ohms) resistors with a 1 A current source into node "1" (returning through ground "0"). Build the nodal conductance matrix for the non-ground nodes (sorted by name) and set v to a dictionary from node to voltage, using np.linalg.solve.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A diode with A and = 0.02585 V is driven from V = 5 V through a resistor; sweep the resistor over 100 log-spaced values from 100 Ω to 100 kΩ. For each, find the diode voltage by bisection (to 1e-12 V) and set vd to the array of diode voltages. Then fit against with np.polyfit and set VT_fit from the slope. (Rs = 1 is not used; it's there to vary your numbers.)
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