A4 Python for engineers · Practice
Random numbers and Monte Carlo
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
With rng = np.random.default_rng(s) and N = 100000, draw top and bottom resistors of a 10 kΩ/10 kΩ divider as uniform within ±t = 1%, top first. Set r to the array of ratios, sd to their standard deviation, and frac to the fraction within ±t/2 % 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
Model R = 10 kΩ ±tR% and C = 10 nF ±tC% as normal with = tolerance/3. With rng = np.random.default_rng(0) and 200,000 draws (R first), set fc to the corner frequencies and yld to the fraction within ±spec% of the nominal corner.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A Monte Carlo run of N = 1000 boards finds a yield of p = 0.95. Set se to the standard error of that estimate, and N4 to how many boards would halve it.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Estimate with rng = np.random.default_rng(s) and 1,000,000 points drawn as x, y = rng.uniform(-1, 1, (2, N)). Set pi_est and err to its absolute error.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An LED driver has . Model 100,000 boards with rng = np.random.default_rng(s), drawing in this order: Vs normal with mean 5 V and = 0.05 V, Vf normal with mean 2.0 V and = 0.05 V, and R uniform within ±tR = 1% of 150 Ω. Set I to the currents, yield_ to the fraction within 18 to 22 mA, and worst to the largest current.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A Monte Carlo yield estimate near 0.95 has a standard error of . How many simulated boards give a standard error of 0.5%?
Check
With rng = np.random.default_rng(s), draw 10,000 values from a normal distribution with mean 5 and standard deviation 0.1. Set p95 to the 95th percentile with np.percentile.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For two independent ±t% uniform resistors in series, set worst to the worst-case relative error of the total, in percent.
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