Tensors, Solving Matrix Equations Iteratively, Backpropagation for Neural Networks and Gradient-Descent Regression
Solving Matrix Equations: Elimination, LU, Jacobi and Gauss–Seidel
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 ρ.
| Method | Cost / convergence | Needs | Use |
|---|---|---|---|
| Gauss elimination | ≈ n³/3 operations | Pivoting for stability | Small dense systems |
| LU | n³/3 once, then n² per b | Same | Many right-hand sides |
| Jacobi | Linear, rate ρ_J | Diagonal dominance | Parallel, sparse |
| Gauss–Seidel | Linear, faster than Jacobi (ρ_J² if consistently ordered) | Diagonal dominance | Sparse, sequential |
- Spectral radius 0.5359
- 15 sweeps to error below 10⁻⁴
- 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
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.
| Activation | f(z) | f′(z) | Note |
|---|---|---|---|
| Sigmoid | 1/(1 + e^(−z)) | σ(1 − σ) | Max slope 0.25; vanishing gradient |
| Tanh | tanh z | 1 − tanh² z | Zero-centred; max slope 1 |
| ReLU | max(0, z) | 0 or 1 | Cheap; units can "die" |
- Forward passz = Wa + b, a = f(z)
- Output error signal δ
- Backward sweepChain rule, layer by layer
- Weight gradients ∂E/∂w
- Update w ← w − η∂E/∂w
- ↻ 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
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.
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.
A rank-2 tensor in three dimensions has how many components, and a rank-3 tensor how many?
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.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.The principal stresses of σ = [[50, 30], [30, −10]] MPa are:
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
Which condition is sufficient for the Jacobi and Gauss–Seidel iterations to converge for any starting vector?
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).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.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:
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.)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₁.The maximum value of the derivative of the logistic sigmoid is 0.25. The main consequence for deep networks of sigmoid layers is:
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.Which statements about training a neural network by gradient descent are correct?
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.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.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.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.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.For the ReLU activation f(x) = max(0, x), the gradient passed back through a unit whose input is negative is
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.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.If the learning rate in gradient descent is set far too large, the most likely result is that
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 η.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.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.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.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.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.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.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.Gradient descent w ← w − η∇f is applied to f(w) = ½wᵀAw with A symmetric positive definite. Which statements are correct?
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.