Translate a covariance requirement into an equation
Suppose \(z\) is a zero-mean random vector with identity covariance. Let a deterministic device produce \(y=Xz\). Multiplying out \(yy^T\) and averaging gives
A target covariance \(A\) is symmetric and positive semidefinite by construction. Restrict the exercise to positive definite targets. They correspond to genuine variation in every direction and allow us to discuss an invertible square root. The notebook uses two dimensionless readout channels, so mixing their coordinates has a defined physical meaning.
If the sole purpose were generating random samples, any factor satisfying \(XX^T=A\) would do. Indeed, replacing \(X\) by \(XQ\) for an orthogonal \(Q\) leaves this output covariance alone. We make an extra modelling decision: the calibration transform should be symmetric and positive. This picks a distinguished factor that stretches along principal axes and introduces no orthogonal rotation. The equation becomes \(X^2=A\). A Cholesky factor produces the correct covariance too, but squaring that generally triangular factor is a different calculation.
To see existence, diagonalise \(A=Q\Lambda Q^T\). The matrix \(S=Q\sqrt{\Lambda}Q^T\) squares to \(A\). For uniqueness on the positive branch, a putative root commutes with its own square and consequently preserves each eigenspace of \(A\). Within an eigenspace of eigenvalue \(a>0\), a symmetric positive root has only positive eigenvalues whose squares equal \(a\). It must act there as \(\sqrt a\) times the identity. Repeated eigenvalues leave the choice of basis in that subspace free while the positive root itself stays fixed.
Differentiate before choosing a linear solver
For scalar data, expanding \((x+h)^2=x^2+2xh+h^2\) supplies Newton's familiar correction. For matrices write every factor in its original order. The cross terms are \(XH\) and \(HX\). They coincide only under a commutation condition. The first variation is therefore a linear map on a whole matrix, not multiplication by a single derivative matrix on the left.
Set the linearised residual to zero. The correction \(H\) solves the Sylvester equation \(XH+HX=A-X^2\). If \(X\) and the right-hand side are symmetric, the transpose of any solution satisfies the same equation. Existence and uniqueness on the positive branch therefore guarantee a symmetric correction. This argument is a practical implementation check: an update with substantial antisymmetric part could not have been obtained by solving this particular Newton equation accurately.
Diagonalise the current iterate \(X=U\,\mathrm{diag}(d_i)U^T\). Write a tilde for the representation in the \(U\) basis. The \(ij\) entry of \(XH+HX\) becomes \((d_i+d_j)\widetilde H_{ij}\). We can solve entry by entry and transform back. All denominators are positive if \(X\) is positive. The minimum denominator is \(2d_{\min}\); as the smallest stretch approaches zero, a fixed residual can request a large correction in a weakly varying direction. This sensitivity also appears when estimating a covariance from data near a rank loss.
A tilted measurement that defeats the scalar update
Choose the axes of the current iterate for a hand calculation and take \(X=\operatorname{diag}(2,1)\). Suppose the target covariance measured in these axes is \(A=\bigl(\begin{smallmatrix}5&1\\1&2\end{smallmatrix}\bigr)\). It is positive because its determinant is nine and its first diagonal entry is positive. Then \(R=A-X^2\) has all four entries equal to one. The diagonal corrections are \(1/4\) and \(1/2\). Both off-diagonal corrections equal \(1/3\), so the update rotates the stretching axes as well as changing their magnitudes.
What if one used \(2XH=R\)? The two off-diagonal entries of that candidate would be \(1/4\) and \(1/2\) instead. It fails even the requirement that the correction be symmetric. Its upper off-diagonal Sylvester residual is
A code that checks only whether \(2XH-R\) vanishes would report success on exactly the wrong derivative. A well-chosen verification problem needs noncommuting matrices. If both the initial and target matrices are diagonal in the same basis, the extra terms disappear from this test.
With the correct correction, substitution into the expanded formula gives \(F(X+H)=H^2\) in exact arithmetic. This provides a surprisingly inexpensive check: solve one linear system, form the new nonlinear residual, and compare it with the square of the correction. For the hand example the first diagonal entry of \(H^2\) equals
The initial value of \(F_{11}\) was \(-1\). There is no reason every residual component should decrease at every remote initial condition, but this one-step identity holds regardless of the starting error.
Which errors does quadratic convergence describe?
Near the desired root, the inverse Sylvester map is bounded if the smallest eigenvalue of the iterate stays away from zero. In Frobenius norm the correction obeys \(\|H\|_F\le\|R\|_F/(2d_{\min})\). Together with submultiplicativity and \(F(X+H)=H^2\), this yields a bound on the next residual proportional to the square of the preceding one. The proportionality constant depends on the current scale. This explains the near-doubling of correct digits late in the calculation and also why such a rule cannot be assumed for an arbitrary ill-conditioned target from the first step.
For this particular problem even preservation of the positive branch can be understood. Rearrange the equation for \(Y=X+H\) to give
The right side is positive. In an eigenbasis of positive \(X\), the inverse operator admits the integral representation \(Y=\int_0^\infty e^{-tX}(A+X^2)e^{-tX}\,dt\). Differentiate the integrand and integrate over the half line to verify the equation; the exponential vanishes at infinity. Each integrand is positive definite for finite \(t\). Thus an exact step from positive \(X\) yields positive \(Y\). This is specific to the equation and branch presently being solved.
Open full-size diagramUse a residual, a branch check and an independent solver
Run the notebook with target eigenvalues nine and one and a starting tilt of 35 degrees. The desired standard-deviation stretches are three and one. The plotted circle has radius one in input coordinates; the output contour has those semiaxes only for the target factor. A unit-radius contour in two dimensions is not a statement that 68 per cent of samples are enclosed. That probability requires a specified distribution and dimension. Read the ellipse here as a drawing of the linear transformation.
Set the initial angle to zero and repeat the comparison between the full and scalar-style derivatives. They now agree because \(X\) and \(A\) share eigenvectors. Next switch back to the tilted start and increase the target anisotropy. Observe the size of the first correction and the number of accepted steps. At the final iterate compare its square with the target and check its smallest eigenvalue. A negative definite square root could have residual zero as well. The sign constraint is therefore informative even for a solver that seems to have converged perfectly.
The optional OneSimulation calculation in the notebook takes an independent route through the derivative. Stacking the columns of \(H\) converts the Sylvester map into \(I\otimes X+X^T\otimes I\). A dense linear solve of the resulting four-by-four system should reproduce the rotated entrywise correction. Stacking rows while building the column-stacking operator would generally be a mistake. Large matrices would make the explicit Kronecker matrix expensive; the small example is valuable because it lets us compare two independently constructed maps directly.
Predict the effect of a small covariance error
The same derivative describes uncertainty in the result. If a measured target changes by a small symmetric matrix \(E\) and the root changes from \(S\) to \(S+\Delta\), expand the defining equation to obtain
Errors in the target's small-eigenvalue direction have a comparatively large effect on the fitted stretch there. For target eigenvalues nine and one, a diagonal covariance error of 0.06 produces first-order stretch errors of 0.01 or 0.03, depending on its direction. The relative errors differ by an additional factor of three because the original stretches are three and one.
An off-diagonal perturbation has a different interpretation. In the target eigenbasis its leading root entry is divided by the sum of the two stretches, here four. It changes the orientation of the ellipse at first order while leaving the axis lengths unchanged at that order for distinct eigenvalues. The distinction explains how visually similar residual norms can imply rather different changes to a calibrated instrument. It also shows what to record when comparing two repeat measurements: the directions of their errors should accompany the overall covariance norm.
Tutorial on branches, scaling and derivatives
1. Take \(A=\operatorname{diag}(4,9)\). Give two distinct symmetric roots and identify which one the stated calibration selects.
Work through the solution
Both \(\operatorname{diag}(2,3)\) and \(\operatorname{diag}(-2,3)\) square to \(A\). Only the first is positive definite. The residual cannot distinguish them; a test of the eigenvalues or a positive-branch construction is needed.
2. At \(X=\operatorname{diag}(3,0.2)\), compare corrections produced by equal residual entries of magnitude 0.01 on each diagonal.
Work through the solution
The first diagonal correction has magnitude \(0.01/6\simeq0.00167\). The second has magnitude \(0.01/0.4=0.025\). Thus identical absolute covariance errors require corrections differing by a factor of fifteen in the two stretch directions.
3. In the tilted hand example, what is the predicted first off-diagonal entry of the updated nonlinear residual? How would one use it to distinguish a failed linear solve from an ordinary Newton truncation?
Work through the solution
The correct \(H^2_{12}\) equals
With an inexact solve, \(F(X+H)-H^2=F(X)+XH+HX\) equals the residual of the linearised equation. Its norm tests solver accuracy separately from the nonlinear term intentionally left after a Newton step.
Further reading · Nicholas Higham, Newton's method for the matrix square root
Change parameters · Newton's method for an unknown covariance square root
Change one input at a time and compare the recalculated curves with the argument above. The browser evaluates this small model locally; the accompanying numerical values state its assumptions and reference checks. Reset restores the reference inputs, and the data can be downloaded as CSV.