Tensors, Solving Matrix Equations Iteratively, Backpropagation for Neural Networks and Gradient-Descent Regression

Section 1 of the Instrumentation Engineering (IN) paper names three items the shared mathematics chapters do not teach: tensors under Linear Algebra, and the solution of matrix equations and backpropagation for neural networks under Numerical Methods. A tensor is a multilinear object whose components transform in a fixed way under a rotation of axes; a rank-2 tensor such as the stress state [[50, 30], [30, −10]] MPa has components that change with the axes (σ′ₓₓ = 60.98 MPa at 30°) while its trace (40) and its principal values (62.43 and -22.43 MPa) do not. A matrix equation Ax = b is solved by elimination or LU, or iteratively by Jacobi and Gauss–Seidel when A is diagonally dominant; on a 3 × 3 example Gauss–Seidel needs 6 sweeps to Jacobi's 15. Backpropagation is the chain rule applied layer by layer: for a one-hidden-unit sigmoid network at x = 1 the gradient is ∂E/∂w₁ = -0.0887, confirmed by a finite difference, and one step of η = 0.5 lowers the error from 0.0713 to 0.0429.
Overview

Tensors: Rank, Transformation, Invariants and Index Notation

2 min read · 1 part

A tensor is a quantity whose components in any coordinate frame determine its components in any other by a fixed rule, so that the physical object is frame-independent. Rank (order) is the number of indices: a scalar (temperature) is rank 0, a vector (velocity, field) rank 1, and a linear map between vectors (stress, strain, inertia, conductivity, the dielectric tensor) rank 2, with n^r components in n dimensions (9 for rank 2, 27 for rank 3 in 3-D). Under a rotation with orthogonal matrix a: a vector transforms v′ᵢ = aᵢⱼvⱼ and a rank-2 tensor T′ᵢⱼ = aᵢₖaⱼₗTₖₗ, i.e. T′ = aTaᵀ. Einstein notation sums over a repeated index: aᵢbᵢ is the dot product, Tᵢⱼvⱼ a matrix–vector product, and contraction (setting two indices equal and summing) lowers the rank by 2, so Tᵢᵢ is the trace. The Kronecker delta δᵢⱼ is the identity tensor; the Levi-Civita symbol εᵢⱼₖ gives the cross product (a × b)ᵢ = εᵢⱼₖaⱼbₖ. Any rank-2 tensor splits uniquely into a symmetric part (Tᵢⱼ + Tⱼᵢ)/2 and an antisymmetric part (Tᵢⱼ − Tⱼᵢ)/2; stress and strain are symmetric.

Worked: the stress tensor. σ = [[50, 30], [30, −10]] MPa (σₓ = 50, σ_y = −10, τ = 30). Rotating the axes by θ = 30°: σ′ₓₓ = σₓcos²θ + σ_ysin²θ + 2τ sinθ cosθ = 37.5 − 2.5 + 25.98 = 60.98 MPa, σ′_yy = -20.98 MPa. The components changed, yet the invariants did not: trace σ′ₓₓ + σ′_yy = 40 MPa = 50 − 10, and the determinant −1400 is also unchanged. The principal values are the eigenvalues, (σₓ + σ_y)/2 ± √(((σₓ − σ_y)/2)² + τ²) = 20 ± 42.43 = 62.43 and -22.43 MPa, on axes rotated by θ_p = ½ arctan(2τ/(σₓ − σ_y)) = 22.5° where the shear vanishes. The maximum shear is the radius 42.43 MPa (Mohr's circle). The same eigenproblem gives the principal axes of inertia, of the conductivity tensor of an anisotropic crystal and of a strain-gauge rosette.

ObjectRankComponents (3-D)Example
Scalar01Temperature, charge
Vector13Velocity, E field
Rank-2 tensor29Stress, strain, conductivity
Rank-3 tensor327Piezoelectric tensor, ε_ijk

A tensor is a quantity whose components in any coordinate frame determine its components in any other by a fixed rule, so that the physical object is frame-independent. Rank (order) is the…

Solving Matrix Equations: Elimination, LU, Jacobi and Gauss–Seidel

2 min read · 3 parts

Gauss elimination reduces Ax = b to an upper triangle by row operations and back-substitutes; it costs about n³/3 multiplications. A zero or tiny pivot demands partial pivoting (swap in the row with the largest entry in the column), otherwise rounding error explodes. LU decomposition records the multipliers: A = LU with L unit lower triangular, so each new right-hand side costs only n² operations and det A = product of the pivots. Example: A = [[2, 1], [4, 3]] gives L = [[1, 0], [2, 1]], U = [[2, 1], [0, 1]], det A = 2 × 1 = 2. The system is ill-conditioned when the condition number κ = ‖A‖‖A⁻¹‖ is large: a tiny change in b then makes a huge change in x. Iterative methods suit large sparse systems: Jacobi uses only the previous iterate, xᵢ⁽ᵏ⁺¹⁾ = (bᵢ − Σj≠iaᵢⱼxⱼ⁽ᵏ⁾)/aᵢᵢ; Gauss–Seidel uses the newest values immediately. Both converge if A is strictly diagonally dominant (|aᵢᵢ| > Σ|aᵢⱼ|) — sufficient, not necessary — or, in general, if the iteration matrix has spectral radius < 1.

Worked. A = [[4, 1, 1], [1, 5, 2], [1, 2, 6]], b = [6, 8, 9]ᵀ (diagonally dominant). The exact solution is x = [1.0000, 1.0000, 1.0000]. Starting from zero, Jacobi's first three iterates are [1.5000, 1.6000, 1.5000], [0.7250, 0.7000, 0.7167], [1.1458, 1.1683, 1.1458], and Gauss–Seidel's are [1.5000, 1.3000, 0.8167], [0.9708, 1.0792, 0.9785], [0.9856, 1.0115, 0.9986]. To an error below 10⁻⁴ Jacobi takes 15 sweeps and Gauss–Seidel 6; their spectral radii are ρ_J = 0.5359 and ρ_GS = 0.1291, smaller, so Gauss–Seidel needs fewer sweeps (for a consistently ordered matrix, such as a tridiagonal one, exactly ρ_GS = ρ_J², half the sweeps). The error shrinks by ρ each sweep, so the number of sweeps needed is about ln(tolerance)/ln ρ.

MethodCost / convergenceNeedsUse
Gauss elimination≈ n³/3 operationsPivoting for stabilitySmall dense systems
LUn³/3 once, then n² per bSameMany right-hand sides
JacobiLinear, rate ρ_JDiagonal dominanceParallel, sparse
Gauss–SeidelLinear, faster than Jacobi (ρ_J² if consistently ordered)Diagonal dominanceSparse, sequential
Jacobi versus Gauss–Seidel on the worked system
Jacobi
  • Spectral radius 0.5359
  • 15 sweeps to error below 10⁻⁴
Gauss–Seidel
  • Spectral radius 0.1291
  • 6 sweeps

Gauss elimination reduces Ax = b to an upper triangle by row operations and back-substitutes; it costs about n³/3 multiplications. A zero or tiny pivot demands partial pivoting (swap in the…

Backpropagation for Neural Networks

2 min read · 2 parts

A feed-forward network computes z = Wa + b and a = f(z) layer by layer; training minimises a loss E over the weights by gradient descent, w ← w − η∂E/∂w. Backpropagation computes every ∂E/∂w with one backward sweep of the chain rule, reusing the forward values. Define the error signal at a layer δ = ∂E/∂z; at the output δ = ∂E/∂a × f′(z), and for the previous layer δ^(l) = (W^(l+1))ᵀδ^(l+1) ⊙ f′(z^(l)), with the weight gradient ∂E/∂W^(l) = δ^(l)(a^(l−1))ᵀ and the bias gradient δ^(l). The derivative of the sigmoid is σ′ = σ(1 − σ) (maximum 0.25), of tanh 1 − tanh², of ReLU 0 or 1. For squared error E = ½(ŷ − y)² the output error is ŷ − y; for softmax with cross-entropy it is again simply ŷ − y.

Worked (one hidden unit). x = 1, target y = 1; w₁ = 0.5, b₁ = 0, w₂ = 1, b₂ = 0; hidden sigmoid, linear output. Forward: z₁ = 0.5, h = σ(z₁) = 0.6225, ŷ = w₂h = 0.6225, E = ½(ŷ − y)² = 0.0713. Backward: δ_out = ŷ − y = -0.3775; ∂E/∂w₂ = δ_out·h = -0.2350; ∂E/∂h = δ_out·w₂ = -0.3775; δ₁ = ∂E/∂h × h(1 − h) = -0.0887; ∂E/∂w₁ = δ₁x = -0.0887. A central finite difference [E(w₁ + ε) − E(w₁ − ε)]/2ε gives the same -0.0887 — the standard gradient check. Update with η = 0.5: w₁ = 0.5444, w₂ = 1.1175, and the error falls to 0.0429. Pitfalls: because σ′ ≤ 0.25 the error signal shrinks by at least 4× per sigmoid layer — through 10 layers by 0.25¹⁰ = 9.5e-07, the vanishing-gradient problem, which ReLU and careful initialisation reduce; a large η overshoots and diverges, a small one crawls; and a network trained to near-zero error on its training set may overfit, so judge it on held-out data.

Activationf(z)f′(z)Note
Sigmoid1/(1 + e^(−z))σ(1 − σ)Max slope 0.25; vanishing gradient
Tanhtanh z1 − tanh² zZero-centred; max slope 1
ReLUmax(0, z)0 or 1Cheap; units can "die"
One training step by backpropagation
  1. Forward passz = Wa + b, a = f(z)
  2. Output error signal δ
  3. Backward sweepChain rule, layer by layer
  4. Weight gradients ∂E/∂w
  5. Update w ← w − η∂E/∂w
  6. ↻ Forward pass

A feed-forward network computes z = Wa + b and a = f(z) layer by layer; training minimises a loss E over the weights by gradient descent, w ← w − η∂E/∂w. Backpropagation computes every…

Gradient Descent as an Iterative Method for Regression, and Training Discipline

1 min read · 2 parts

Linear regression ŷ = wx + b minimises Σ(ŷᵢ − yᵢ)². It has the closed form (normal equations) but the same minimum can be reached iteratively, which is how neural networks are trained. For the data (1, 2), (2, 3), (3, 5), (4, 4): least squares gives w = 0.80, b = 1.50 and the correlation coefficient r = 0.8000. Gradient descent on the mean squared error starts from w = b = 0 with η = 0.05: ∂E/∂w = 2·mean[(ŷ − y)x], ∂E/∂b = 2·mean[ŷ − y], so after one step w = 0.975, b = 0.350, and after many steps it settles at w = 0.800, b = 1.500, the closed-form answer. For a quadratic error surface the step η must be below 2/λ_max of the Hessian or the iteration diverges. Stochastic gradient descent uses one sample (or a small batch) per step — noisier, much cheaper per step, and good at escaping shallow minima; feature scaling keeps the surface round and speeds convergence.

🎯 Why this belongs under numerical methods
Gauss–Seidel, Newton's method and gradient descent are one idea: replace "solve it exactly" by "improve a guess repeatedly until the change is below a tolerance". The questions are the same — does it converge, how fast, and how many steps.
⚠️ Training error is not test error
A model with enough parameters can drive training error to zero by memorising noise. Keep validation data apart, stop when validation error rises, and use regularisation (weight decay) to penalise large weights. For instrumentation the practical form is calibrating a sensor on a subset of reference points and checking on the rest.

Linear regression ŷ = wx + b minimises Σ(ŷᵢ − yᵢ)². It has the closed form (normal equations) but the same minimum can be reached iteratively, which is how neural networks are trained. For…

Key takeaways

  • A tensor's components change with the axes but its invariants (trace, determinant, principal values) do not; rank-2 tensors transform as T′ = aTaᵀ and n^r components in n dimensions.
  • Einstein notation sums repeated indices; contraction lowers rank by 2; stress and strain are symmetric rank-2 tensors with principal values equal to eigenvalues.
  • Gauss elimination ≈ n³/3, LU reuses factors for many right-hand sides; Jacobi and Gauss–Seidel converge for diagonally dominant matrices, and Gauss–Seidel is faster (ρ_GS = ρ_J² for consistently ordered matrices).
  • Backpropagation is the chain rule: δ^(l) = (W^(l+1))ᵀδ^(l+1) ⊙ f′(z^(l)), ∂E/∂W = δaᵀ; check by finite differences; sigmoid slope ≤ 0.25 causes vanishing gradients.
  • Gradient descent reaches the least-squares answer iteratively if η < 2/λ_max; judge a trained model on held-out data, not on training error.

Practice questions (24)

Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.

  1. A rank-2 tensor in three dimensions has how many components, and a rank-3 tensor how many?

    1. 9 and 9
    2. 9 and 27
    3. 3 and 9
    4. 6 and 10
    Show answer

    Answer: B — 9 and 27

    A rank-r tensor in n dimensions has n^r components: 3² = 9 and 3³ = 27. A symmetric rank-2 tensor has only 6 independent components, the tempting second figure.
  2. The stress tensor σ = [[50, 30], [30, −10]] MPa is referred to axes rotated by 30°. The new normal stress σ′ₓₓ in MPa (two decimals) is:

    Numerical answer — type the value.

    Show answer

    Answer: 60.98

    σ′ₓₓ = 50cos²30° + (−10)sin²30° + 2 × 30 sin30° cos30° = 37.5 − 2.5 + 25.98 = 60.98 MPa. σ′_yy = -20.98 MPa, and the sum stays 40.
  3. The principal stresses of σ = [[50, 30], [30, −10]] MPa are:

    1. 62.4 and -22.4 MPa
    2. 80 and −40 MPa
    3. 50 and −10 MPa
    4. 40 and 0 MPa
    Show answer

    Answer: A — 62.4 and -22.4 MPa

    20 ± √(30² + 30²) = 20 ± 42.43 = 62.43 and -22.43 MPa, which sum to 40 (the trace). 50 and −10 are the unrotated normal stresses, not the extremes.
Show the other 21 questions
  1. Which condition is sufficient for the Jacobi and Gauss–Seidel iterations to converge for any starting vector?

    1. A is symmetric
    2. A is strictly diagonally dominant
    3. A has positive entries
    4. det A = 1
    Show answer

    Answer: B — A is strictly diagonally dominant

    Strict diagonal dominance forces the iteration matrix norm below 1. Symmetry or positive entries alone give no guarantee (a symmetric matrix can make Jacobi diverge).
  2. For A = [[2, 1], [4, 3]] the LU factorisation (without pivoting) has U = [[2, 1], [0, 1]]. The determinant of A is:

    Numerical answer — type the value.

    Show answer

    Answer: 2

    det A = det L × det U = 1 × (2 × 1) = 2; directly, 2 × 3 − 1 × 4 = 2. The multiplier is 4/2 = 2.
  3. For a consistently ordered matrix (for example a tridiagonal one) whose Jacobi iteration matrix has spectral radius ρ, the Gauss–Seidel iteration matrix has spectral radius:

    1. ρ
    2. √ρ
    3. ρ²
    4. 2ρ
    Show answer

    Answer: C — ρ²

    For consistently ordered matrices ρ_GS = ρ_J², so each Gauss–Seidel sweep shrinks the error as much as two Jacobi sweeps and the sweep count is about halved. (For the 3 × 3 example here, which is not tridiagonal, the counts are 6 against 15.)
  4. A network has one sigmoid hidden unit h = σ(w₁x) and a linear output ŷ = w₂h. For x = 1, y = 1, w₁ = 0.5, w₂ = 1 and E = ½(ŷ − y)², the gradient ∂E/∂w₁ is (four decimals, with its sign):

    Numerical answer — type the value.

    Show answer

    Answer: -0.0887

    h = σ(0.5) = 0.6225; ŷ − y = -0.3775; ∂E/∂w₁ = (ŷ − y) w₂ h(1 − h) x = -0.3775 × 1 × 0.2350 = -0.0887. It is negative, so gradient descent will increase w₁.
  5. The maximum value of the derivative of the logistic sigmoid is 0.25. The main consequence for deep networks of sigmoid layers is:

    1. gradients shrink by at least 4× per layer going backwards (vanishing gradient)
    2. the loss becomes non-differentiable
    3. gradients explode
    4. training becomes exact in one step
    Show answer

    Answer: A — gradients shrink by at least 4× per layer going backwards (vanishing gradient)

    Each backward pass through a sigmoid multiplies the error signal by σ′ ≤ 0.25, so after 10 layers the factor is at most 0.25¹⁰ ≈ 10⁻⁶. ReLU (slope 1 when active) and good initialisation mitigate this.
  6. Which statements about training a neural network by gradient descent are correct?

    1. A gradient check compares the analytic gradient with a finite-difference estimate
    2. A learning rate that is too large can make the loss diverge
    3. Backpropagation computes all weight gradients with one backward sweep using the chain rule
    4. Zero training error guarantees zero error on new data
    Show answer

    Answer: A — A gradient check compares the analytic gradient with a finite-difference estimate; B — A learning rate that is too large can make the loss diverge; C — Backpropagation computes all weight gradients with one backward sweep using the chain rule

    The first three are standard. Zero training error can mean memorised noise (over-fitting), so held-out error is the real test.
  7. For the data (1, 2), (2, 3), (3, 5), (4, 4) the least-squares line is ŷ = wx + b. The slope w is (two decimals):

    Numerical answer — type the value.

    Show answer

    Answer: 0.80

    x̄ = 2.5, ȳ = 3.5; S_xy = 4.0 (sum of products of deviations), S_xx = 5.0; w = S_xy/S_xx = 0.80, b = ȳ − w x̄ = 1.50. Gradient descent converges to the same line.
  8. In three dimensions, with the summation convention, the contraction δᵢᵢ of the Kronecker delta equals ____.

    Numerical answer — type the value.

    Show answer

    Answer: 3

    δᵢᵢ = δ₁₁ + δ₂₂ + δ₃₃ = 3, the trace of the 3 × 3 identity. Answering 1 reads δᵢᵢ as a single component instead of a sum over the repeated index.
  9. A symmetric rank-2 tensor in three dimensions has how many independent components? ____

    Numerical answer — type the value.

    Show answer

    Answer: 6

    Symmetry σᵢⱼ = σⱼᵢ leaves 3 diagonal + 3 off-diagonal = 6 independent components (n(n + 1)/2). Answering 9 counts all entries, ignoring the symmetry; an antisymmetric tensor would have 3.
  10. For 4x + y = 9, x + 3y = 7, one Jacobi iteration from (x, y) = (0, 0) gives x = ____ (two decimals).

    Numerical answer — type the value.

    Show answer

    Answer: 2.25

    x⁽¹⁾ = (9 − y⁽⁰⁾)/4 = 9/4 = 2.25 (and y⁽¹⁾ = 7/3). Writing 9, dropping the division by the diagonal 4, is the slip; the exact solution is x = 20/11 ≈ 1.82.
  11. For the ReLU activation f(x) = max(0, x), the gradient passed back through a unit whose input is negative is

    1. 1
    2. 0
    3. 0.25
    4. equal to the input
    Show answer

    Answer: B — 0

    For x < 0 the ReLU is flat, so f′(x) = 0 and no gradient flows; units stuck there are the "dying ReLU" problem. 0.25 is the maximum derivative of the sigmoid, a different activation.
  12. Gradient descent on f(w) = w² starts at w₀ = 3 with learning rate 0.1. After one step, w₁ = ____ (one decimal).

    Numerical answer — type the value.

    Show answer

    Answer: 2.4

    w₁ = w₀ − η f′(w₀) = 3 − 0.1 × 6 = 2.4. Using f′ = w (forgetting the 2) gives 2.7; stepping along +f′ instead of −f′ gives 3.6 and moves uphill.
  13. If the learning rate in gradient descent is set far too large, the most likely result is that

    1. convergence becomes slow but steady
    2. the minimum moves to a new location
    3. the gradient becomes exactly zero
    4. the iterates oscillate or diverge instead of settling
    Show answer

    Answer: D — the iterates oscillate or diverge instead of settling

    Each step overshoots the minimum by more than it corrects, so the error grows. Slow, steady convergence is the symptom of a learning rate that is too SMALL; the minimum itself is a property of f, not of η.
  14. For the symmetric tensor T = [[2, 1, 0], [1, 3, 0], [0, 0, 4]], the third invariant (its determinant) is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 20

    det T = 4 × (2 × 3 − 1 × 1) = 20, which also equals the product of the principal values. Answering 24 multiplies the diagonal only, ignoring the off-diagonal coupling; the first invariant (trace) would be 9.
  15. For 4x + y = 9, x + 3y = 7, one Gauss–Seidel iteration from (0, 0), updating x first, gives y = ____ (three decimals).

    Numerical answer — type the value.

    Show answer

    Answer: 1.583

    x⁽¹⁾ = 9/4 = 2.25 is used at once: y⁽¹⁾ = (7 − 2.25)/3 = 1.583. Using the old x = 0 gives 2.333, which is the Jacobi value; using the latest values is the whole difference between the two methods.
  16. The 2-norm condition number of A = [[2, 0], [0, 0.5]] is ____.

    Numerical answer — type the value.

    Show answer

    Answer: 4

    κ₂ = σ_max/σ_min = 2/0.5 = 4: relative errors in b can be magnified up to 4 times in x. Answering 1 takes the determinant (2 × 0.5 = 1) as a measure of conditioning, which it is not.
  17. A linear neuron ŷ = wx + b with loss L = ½(ŷ − t)² has w = 0.5, b = 0, input x = 2 and target t = 2. The gradient ∂L/∂w is ____.

    Numerical answer — type the value.

    Show answer

    Answer: -2

    ŷ = 1, so ∂L/∂w = (ŷ − t)x = (1 − 2)(2) = −2; gradient descent will therefore increase w. Answering −1 gives ∂L/∂ŷ (or ∂L/∂b) and forgets the chain-rule factor x.
  18. Gradient descent on f(w) = 2w² (so f″ = 4) is stable only for learning rates 0 < η < η_max. The value of η_max is ____ (one decimal).

    Numerical answer — type the value.

    Show answer

    Answer: 0.5

    w ← w − 4ηw = (1 − 4η)w converges iff |1 − 4η| < 1, i.e. η < 2/4 = 0.5. Answering 0.25 gives the one-step (fastest) rate 1/f″, not the stability limit.
  19. For A = [[4, 1], [1, 3]], the spectral radius of the Jacobi iteration matrix −D⁻¹(L + U) is ____ (three decimals).

    Numerical answer — type the value.

    Show answer

    Answer: 0.289

    B_J = [[0, −1/4], [−1/3, 0]] has eigenvalues ±√(1/12), so ρ = 0.289 < 1 and Jacobi converges. Gauss–Seidel would give ρ² = 0.083; quoting that value confuses the two iteration matrices.
  20. A softmax output with cross-entropy loss has logits z = (2, 1, 0) and the true class is the first. The gradient ∂L/∂z₁ (three decimals) is ____.

    Numerical answer — type the value.

    Show answer

    Answer: -0.335

    For softmax + cross-entropy, ∂L/∂zᵢ = pᵢ − yᵢ. p₁ = e²/(e² + e + 1) = 0.6652, so the gradient is -0.335. Reporting p₁ itself (0.665) forgets to subtract the one-hot target.
  21. Gradient descent w ← w − η∇f is applied to f(w) = ½wᵀAw with A symmetric positive definite. Which statements are correct?

    1. It converges for every start if and only if 0 < η < 2/λ_max.
    2. With η = 1/λ_min it always reaches the minimum in one step.
    3. A large condition number λ_max/λ_min makes convergence slow.
    4. Stochastic gradient descent estimates ∇f from a subset of the data at each step.
    Show answer

    Answer: A — It converges for every start if and only if 0 < η < 2/λ_max.; C — A large condition number λ_max/λ_min makes convergence slow.; D — Stochastic gradient descent estimates ∇f from a subset of the data at each step.

    Error components evolve as (1 − ηλᵢ)ᵏ, so stability needs |1 − ηλᵢ| < 1 for all i and the slowest mode is set by the conditioning. With η = 1/λ_min the λ_max mode is multiplied by 1 − λ_max/λ_min, which may even exceed 1 in magnitude; one-step convergence happens only when all eigenvalues are equal.