A4 Python for engineers · Practice
Building circuit equations in code
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
Write stamp_R(G, a, b, R) that adds a resistor between nodes a and b to the conductance matrix G in place, with node 0 as ground (no row) and node in row . Then set G for the starter's random netlist of resistors on 4 nodes.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A current source pushes I = 2 mA into node 1. R1 = 1200 Ω goes from node 1 to ground, R2 = 4700 Ω from node 1 to node 2, and R3 = 8200 Ω from node 2 to ground. Build and with stamps and set v to the solved node voltages.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Build the bridge from the third example with modified nodal analysis: V = 9 V at node 1, 1 kΩ from 1 to 2, from 2 to ground and from 1 to 3, d = 0.9 kΩ from 3 to ground, and a meter of Rg = 10 Ω from 2 to 3. Set x to the solution vector (three voltages, then the source current) and Im to the meter current from node 2 to node 3.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A source Vs = 5 V feeds a divider, R1 = 1000 Ω on top and R2 = 4700 Ω below, and a load RL hangs across R2. Write load_power(RL) that builds and solves the circuit with modified nodal analysis and returns the power in RL. Then search RL over np.logspace(1, 6, 2001) and set RL_best to the value that maximizes the power, and Rth to the divider's Thevenin resistance, R1 in parallel with R2.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
For the starter's random resistor network on 3 nodes with a 1 mA source into node 1, solve for v, then check Kirchhoff's current law yourself: set kcl to an array holding, for each node, the total current leaving it through the resistors minus the current injected there. It should be zero to rounding error.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
Node 1 connects to ground through 2.2 kΩ, to node 2 through 1.2 kΩ and to node 3 through 4.7 kΩ. What is the diagonal entry of the conductance matrix?
Write units the way you normally would: 1.5 S, 1500 mS and 0.0015 kS are the same answer.
Check
Set G to the 1 × 1 conductance matrix (a NumPy array) for two R = 2200 Ω resistors from node 1 to ground, using the stamp rule.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Check
A current source pushes I = 3 mA into node 2 and out of node 1. Set i to the right-hand side vector for a 2-node circuit, in amps.
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