Advanced Octave A21 — Decompositions and effective rank
Advanced GNU Octave with GX-TXT · Module 04
The decomposition to singular values, or SVD, reveals how a matrix acts in different directions of intensity. It is particularly useful to understand why the numerical rank depends on the threshold adopted.
Objectives and prerequisites
We repeat the nearly singular matrix of the lesson A20 and the linear algebra of the introductory course. We calculate the SVD via NUMERIC_API_v1/linear_matrix and check the reconstruction. The test uses GX-TXT dev112-P011-bis and GNU Octave 9.4.0.
Calculate and rebuild
Import rango_svd.m, register it and run it in the Runner.
The API returns separate real and imaginary components for decomposition matrices. The script recomposes them with complex and controls the A = U*S*V' report, where ' indicates the transposition conjugated in Octave.
r = gxtxt_api_call('NUMERIC_API_v1','linear_matrix',{'svd',envelope,[]});
U = complex(r.u_real,r.u_imaginary);
S = complex(r.s_real,r.s_imaginary);
V = complex(r.v_real,r.v_imaginary);
s = diag(S);
fprintf('Framework rank=%d, tolerance=%.3e\n',r.rank,r.rank_tolerance);
fprintf('Rank with threshold 1e-5: %d\n',sum(s>1e-5));
fprintf('Reconstruction error: %.3e\n',norm(A-U*S*V','fro'));
In the test the singular values are about 2 and 5 × 10⁻⁷. With the default tolerance given by the framework, about 8,9 × 10⁻¹⁶, the numerical rank is 2. If we count only the higher values of the 10⁻⁵ teaching threshold, the actual rank becomes 1. The program does not change the internal tolerance of the API: it performs this second count separately.
The reconstruction error observed is about 1,2 × 10⁻¹⁵, small for the example scale. It is a complete decomposition control; it does not show that a subsequent solution is insensitive to noise.
Choose a threshold
The exact algebraic rank is a mathematical property; the numerical rank depends on the precision, scale and criterion chosen. A threshold connected to measuring noise or intended use may be more significant than an arbitrary threshold, but must be motivated and declared. Discarding a small direction can make the calculation more stable and at the same time delete information: it is a methodological choice.
Do not necessarily compare individual carriers U and V element by element between libraries: signs and conventions may vary. It controls rather reconstruction and relevant mathematical relationships.
Exercise
- Why does the
10⁻⁵threshold lead here to a rank count one? - Does the program change the internal tolerance of the framework?
- What does
norm(A-U*S*V','fro')verify?
Worked solution
- The second singular value, about
5 × 10⁻⁷, is lower than the threshold. - No. It reads the default rank and calculates apart an alternative count.
- As the reconstructed matrix differs from the original in the Frobenius rule.
Other steps of this project
- Advanced Octave A75 — Dynamical systems in phase space
- Advanced Octave A81 — Geography of the waves and a 3D surface
- Advanced Octave A82 — Age, sex and demographic inequalities
- Advanced Octave A83 — All-cause mortality, certified COVID deaths and surveillance
- Advanced Octave A84 — A reproducible public account
- Advanced Octave A73 — Optimization landscapes and 3D trajectories