Skip to content
Tactiverge

School/✦ Research Engineer/Week 1

Writing engineering problems as Ax = b

A resistor network, a loaded frame and a cross-talking sensor pair look nothing alike. Why does one line of code solve all three?

About 45 min · 3 goals · Checked by automated tests

1.Why should I care?

Modelling is usually harder than solving. Once a problem is written as Ax = b, decades of reliable numerical software can take over. The skill is choosing unknowns, writing one equation per physical law, and checking the answer makes physical sense.

  • ◇ Set up mesh-current equations for a two-loop resistor circuit as Ax = b.
  • ◇ Set up force-balance equations for a joint and a cross-talk calibration as linear systems.
  • ◇ Check a computed solution by substituting it back (residual b − Ax).

2.Discover

Open the Code Lab. Write a function solve2(A, b) using elimination, then use it on the circuit below. Print the residual b − A·x: it should be (almost exactly) zero.

Can't use the interactive? Read a description instead

This lesson's activity is code-based: write a small elimination solver, apply it to the two-loop circuit A = [[3, −1], [−1, 2]], b = (2, 3), and print the solution (1.4, 2.2) and the residual, which should be near zero.

3.Checkpoint: guided practice

Check what you just discovered before going on. Hints appear after a wrong answer.

Practice 1

For the circuit in the lesson (3I₁ − I₂ = 2, −I₁ + 2I₂ = 3), what is I₂ in amperes?

A

4.Apply it

Model a three-loop resistor ladder of your own design as a 3×3 system. Solve it in the Code Lab, report the residual, and check one current by hand with KVL.

5.Understand

A recipe for modelling

  1. Choose unknowns (loop currents, member tensions, true quantities). 2. Write one equation per physical law: Kirchhoff's voltage law per loop, ΣF = 0 per direction per joint, one sensor model per reading. 3. Collect coefficients into A, knowns into b. 4. Count: as many independent equations as unknowns for a unique answer.

Example: two-loop circuit

A 2 V source drives loop 1 through 2 Ω, and loop 2 contains a 3 V source and 1 Ω. A 1 Ω resistor is shared. KVL in loop 1: 2I₁ + 1(I₁ − I₂) = 2, so 3I₁ − I₂ = 2. Loop 2: 1(I₂ − I₁) + 1·I₂ = 3, so −I₁ + 2I₂ = 3. So A = [[3, −1], [−1, 2]], b = (2, 3), and I = (1.4, 2.2) A.

Always check the residual

Compute r = b − A·x. A tiny residual says you solved the equations you wrote; it does not say they were the right equations. So also sanity-check physics: are currents in a sensible direction, do tensions in a hanging cable come out positive, does the answer change sensibly when you double a source?

Explain it another way

Each equation is one rule the world obeys. Stack all the rules, and the solution is the one set of unknowns that obeys every rule at once.

Worked example 1

Two sensors read r₁ = q₁ + 0.5q₂ and r₂ = 0.25q₁ + q₂. Readings are r = (3, 2.5). Find the true quantities q.

A = [[1, 0.5], [0.25, 1]]. From the first equation q₁ = 3 − 0.5q₂. Substituting: 0.75 − 0.125q₂ + q₂ = 2.5, so q₂ = 2 and q₁ = 2. Residual: (3 − 2 − 1, 2.5 − 0.5 − 2) = (0, 0).

Common mix-ups

  • If the residual is zero, the model is right.
    ✓ A zero residual only verifies the solve. Validation needs physics checks and data.
  • More equations always means a better model.
    ✓ Dependent equations add nothing; inconsistent ones make the system unsolvable. Count independent equations.

6.Practice on your own

Practice, not a test. Wrong answers get a hint and another try.

Practice 2

A frame has 3 unknown member forces at a planar joint. How many independent force-balance equations does that joint give?

Practice 3 · a fresh version every time

Solve −x₁ + x₂ = -3 and 2x₁ + x₂ = -6. What is x1?

Practice 4 · a fresh version every time

Solve A·x = b with A = [[0, 2, 3], [4, 0, 1], [1, -3, 1]] and b = (-8, 4, 13). What is x1?

Practice 5

Your solver returns x with residual ‖b − Ax‖ ≈ 10⁻¹⁴. What have you shown?

7.Predict

Two resistor loops share a 1 Ω resistor. Will the matrix A for the mesh currents be symmetric?

Guess first. Being wrong here is how the surprise works.

8.Reflect

9.Go further

Research mode: limits and open questions

Large sparse systems (millions of unknowns) are solved with sparse LU or iterative methods such as conjugate gradients, but the modelling step is identical to this 2×2 one.

    Concepts: Linear systems, elimination and rank