A4 Python for engineers · Practice
Numerical derivatives and integrals
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
Set fwd and ctr to the forward and central difference estimates of the derivative of at x0 = 1 with step h = 0.1, and e_fwd, e_ctr to their absolute errors against .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For , compute the central difference error for at x0 = 1. Set errs to the list of 13 errors and best_h to the with the smallest one.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Integrate (I0 = 1 A, tau = 2 ms) from 0 to with the trapezoid rule on n = 40 steps. Set Q to the charge in coulombs and err to its relative error against the exact .
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Write simpson(y, h) for an odd number of samples (an even number of slices), and set S to the integral of from 0 to on n = 8 slices, and err to its error against the exact 2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
The starter samples one period of a waveform v at n + 1 = 20 + 1 equally spaced points (the first and last are the same point in the cycle). Using the trapezoid rule written with NumPy slices (not a library integrator), set rms to . Then set exact to the known value: for a sine, for a square wave and for a triangle.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A central difference with step has an error of 4 × 10⁻⁶. Its error goes as while rounding is negligible. What should the error be with the step 10 times smaller?
Check
Sample (A = 1, f = 50 Hz) at 1000 points over one period, and set dv to np.gradient(v, t), its derivative. Set peak to the largest value of dv.
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 1 with the trapezoid rule on n = 20 steps; set T to the result.
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