A4 Python for engineers · Practice
Stepping a system through time
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
Simulate a capacitor charging toward = 6 V from 0 V, with = 1 ms, using Euler's method with = 0.01 ms for 1000 steps. Store the voltages in v (1001 values, starting at 0).
Vs and tau (in ms) are already defined. Work in milliseconds throughout.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Measure Euler's error. Run the discharge from 1 V over twice, with and . Set err1 and err2 to each run's largest error against the exact , and ratio to err1 / err2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
An inductor L = 10 mH in series with R = 10 Ω is switched onto V = 5 V at , so . Step it with Euler's method from for 5 time constants (), with . Set i_end to the final current and err to its 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
Euler's method steps from V with . What is after 3 steps?
Check
Simulate a discharge from 4 V, , = 1 ms, with = 0.05 ms for 400 steps. Set v (401 values).
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Using Euler with = 0.001 ms on a capacitor charging toward 7 V ( = 1 ms), set steps to the number of steps until first reaches 0.8 × 7 V.
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