Cleve Moler is the author of the first MATLAB, one of the founders of MathWorks, and is currently Chief Mathematician at the company. He is the author of two books about MATLAB that are available online. He writes here about MATLAB, scientific computing and interesting mathematics.
I got the idea for these test matrices from Gene Golub years ago, but the mathematical foundation comes from a paper by Divakar Viswanath and Nick Trefethen.
This post is about two MATLAB programs included in the collection from Numerical Computing with MATLAB. The program golub generates badly conditioned integer test matrices. The program lugui is an interactive graphical interface that allows you to experiment with pivot strategies in Gaussian elimination.
A 6-by-6 example
Set the random number generator to the state it has when MATLAB starts and generate a 6-by-6 example.
It's not obvious that this matrix is badly conditioned, but it is.
cond(A)
ans =
3.0115e+12
In case you needed another demonstration that the determinant does not indicate near singularity.
format short
det(A)
ans =
1.0000
The elements of the inverse vary over nine orders of magnitude and show perverse scaling that is a direct consequence of the way this matrix was created.
In a 1998 paper Divakar Viswanath and Nick Trefethen demonstrate that the 2-norm condition number of an n -by- n triangular matrix with normally distributed entries below the diagonal and ones on the diagonal grows exponentially almost surely at a rate c^n with c = 1.30568...
I want my matrices to have integer entries so I use randomly distributed integers, but the exponential behavior must be nearly the same.
Here is the code for golub.
type golub
function A = golub(n)
%GOLUB Badly conditioned integer test matrices.
% GOLUB(n) is the product of two random integer n-by-n matrices,
% one of them unit lower triangular and one unit upper triangular.
% LU factorization without pivoting fails to reveal that such
% matrices are badly conditioned.
% See also LUGUI.
% Copyright 2014 Cleve Moler
% Copyright 2014 The MathWorks, Inc.
s = 10;
L = tril(round(s*randn(n)),-1)+eye(n);
U = triu(round(s*randn(n)),1)+eye(n);
A = L*U;
Experiment with pivoting
Lugui lets you use the mouse to select the pivot elements for Gaussian elimination. Or, you can choose diagonal pivoting, partial pivoting or complete pivoting. Here are animated gifs of these three choices.
Resurrecting ancestors
Diagonal pivoting actually defies the conventional wisdom and picks the smallest possible element at each stage as the pivot, namely 1.0. But this choice means that division by the pivot involves no roundoff. Moreover the choice leads to the reconstruction of the original triangular factors.
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.