comparison scripts/special-matrix/gallery.m @ 20038:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children 941e782d0429
comparison
equal deleted inserted replaced
20037:a1acca0c2216 20038:9fc020886ae9
503 503
504 endfunction 504 endfunction
505 505
506 function C = cauchy (x, y) 506 function C = cauchy (x, y)
507 ##CAUCHY Cauchy matrix. 507 ##CAUCHY Cauchy matrix.
508 ## C = CAUCHY(X, Y), where X, Y are N-vectors, is the N-by-N matrix 508 ## C = CAUCHY(X, Y), where X, Y are N-vectors, is the N-by-N matrix
509 ## with C(i,j) = 1/(X(i)+Y(j)). By default, Y = X. 509 ## with C(i,j) = 1/(X(i)+Y(j)). By default, Y = X.
510 ## Special case: if X is a scalar CAUCHY(X) is the same as CAUCHY(1:X). 510 ## Special case: if X is a scalar CAUCHY(X) is the same as CAUCHY(1:X).
511 ## Explicit formulas are known for DET(C) (which is nonzero if X and Y 511 ## Explicit formulas are known for DET(C) (which is nonzero if X and Y
512 ## both have distinct elements) and the elements of INV(C). 512 ## both have distinct elements) and the elements of INV(C).
513 ## C is totally positive if 0 < X(1) < ... < X(N) and 513 ## C is totally positive if 0 < X(1) < ... < X(N) and
514 ## 0 < Y(1) < ... < Y(N). 514 ## 0 < Y(1) < ... < Y(N).
515 ## 515 ##
516 ## References: 516 ## References:
517 ## N.J. Higham, Accuracy and Stability of Numerical Algorithms, 517 ## N.J. Higham, Accuracy and Stability of Numerical Algorithms,
518 ## Society for Industrial and Applied Mathematics, Philadelphia, PA, 518 ## Society for Industrial and Applied Mathematics, Philadelphia, PA,
519 ## USA, 1996; sec. 26.1. 519 ## USA, 1996; sec. 26.1.
520 ## D.E. Knuth, The Art of Computer Programming, Volume 1, 520 ## D.E. Knuth, The Art of Computer Programming, Volume 1,
521 ## Fundamental Algorithms, second edition, Addison-Wesley, Reading, 521 ## Fundamental Algorithms, second edition, Addison-Wesley, Reading,
522 ## Massachusetts, 1973, p. 36. 522 ## Massachusetts, 1973, p. 36.
523 ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications, 523 ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications,
524 ## Linear Algebra and Appl., 149 (1991), pp. 1-18. 524 ## Linear Algebra and Appl., 149 (1991), pp. 1-18.
525 ## O. Taussky and M. Marcus, Eigenvalues of finite matrices, in 525 ## O. Taussky and M. Marcus, Eigenvalues of finite matrices, in
526 ## Survey of Numerical Analysis, J. Todd, ed., McGraw-Hill, New York, 526 ## Survey of Numerical Analysis, J. Todd, ed., McGraw-Hill, New York,
527 ## pp. 279-313, 1962. (States the totally positive property on p. 295.) 527 ## pp. 279-313, 1962. (States the totally positive property on p. 295.)
528 528
529 if (nargin < 1 || nargin > 2) 529 if (nargin < 1 || nargin > 2)
530 error ("gallery: 1 or 2 arguments are required for cauchy matrix."); 530 error ("gallery: 1 or 2 arguments are required for cauchy matrix.");
531 elseif (! isnumeric (x)) 531 elseif (! isnumeric (x))
532 error ("gallery: X must be numeric for cauchy matrix."); 532 error ("gallery: X must be numeric for cauchy matrix.");
559 C = ones (n) ./ C; 559 C = ones (n) ./ C;
560 endfunction 560 endfunction
561 561
562 function C = chebspec (n, k = 0) 562 function C = chebspec (n, k = 0)
563 ## CHEBSPEC Chebyshev spectral differentiation matrix. 563 ## CHEBSPEC Chebyshev spectral differentiation matrix.
564 ## C = CHEBSPEC(N, K) is a Chebyshev spectral differentiation 564 ## C = CHEBSPEC(N, K) is a Chebyshev spectral differentiation
565 ## matrix of order N. K = 0 (the default) or 1. 565 ## matrix of order N. K = 0 (the default) or 1.
566 ## For K = 0 (`no boundary conditions'), C is nilpotent, with 566 ## For K = 0 (`no boundary conditions'), C is nilpotent, with
567 ## C^N = 0 and it has the null vector ONES(N,1). 567 ## C^N = 0 and it has the null vector ONES(N,1).
568 ## C is similar to a Jordan block of size N with eigenvalue zero. 568 ## C is similar to a Jordan block of size N with eigenvalue zero.
569 ## For K = 1, C is nonsingular and well-conditioned, and its eigenvalues 569 ## For K = 1, C is nonsingular and well-conditioned, and its eigenvalues
570 ## have negative real parts. 570 ## have negative real parts.
571 ## For both K, the computed eigenvector matrix X from EIG is 571 ## For both K, the computed eigenvector matrix X from EIG is
572 ## ill-conditioned (MESH(REAL(X)) is interesting). 572 ## ill-conditioned (MESH(REAL(X)) is interesting).
573 ## 573 ##
574 ## References: 574 ## References:
575 ## C. Canuto, M.Y. Hussaini, A. Quarteroni and T.A. Zang, Spectral 575 ## C. Canuto, M.Y. Hussaini, A. Quarteroni and T.A. Zang, Spectral
576 ## Methods in Fluid Dynamics, Springer-Verlag, Berlin, 1988; p. 69. 576 ## Methods in Fluid Dynamics, Springer-Verlag, Berlin, 1988; p. 69.
577 ## L.N. Trefethen and M.R. Trummer, An instability phenomenon in 577 ## L.N. Trefethen and M.R. Trummer, An instability phenomenon in
578 ## spectral methods, SIAM J. Numer. Anal., 24 (1987), pp. 1008-1023. 578 ## spectral methods, SIAM J. Numer. Anal., 24 (1987), pp. 1008-1023.
579 ## D. Funaro, Computing the inverse of the Chebyshev collocation 579 ## D. Funaro, Computing the inverse of the Chebyshev collocation
580 ## derivative, SIAM J. Sci. Stat. Comput., 9 (1988), pp. 1050-1057. 580 ## derivative, SIAM J. Sci. Stat. Comput., 9 (1988), pp. 1050-1057.
581 581
582 if (nargin < 1 || nargin > 2) 582 if (nargin < 1 || nargin > 2)
583 error ("gallery: 1 to 2 arguments are required for chebspec matrix."); 583 error ("gallery: 1 to 2 arguments are required for chebspec matrix.");
584 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 584 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
585 error ("gallery: N must be an integer for chebspec matrix."); 585 error ("gallery: N must be an integer for chebspec matrix.");
626 endif 626 endif
627 endfunction 627 endfunction
628 628
629 function C = chebvand (m, p) 629 function C = chebvand (m, p)
630 ## CHEBVAND Vandermonde-like matrix for the Chebyshev polynomials. 630 ## CHEBVAND Vandermonde-like matrix for the Chebyshev polynomials.
631 ## C = CHEBVAND(P), where P is a vector, produces the (primal) 631 ## C = CHEBVAND(P), where P is a vector, produces the (primal)
632 ## Chebyshev Vandermonde matrix based on the points P, 632 ## Chebyshev Vandermonde matrix based on the points P,
633 ## i.e., C(i,j) = T_{i-1}(P(j)), where T_{i-1} is the Chebyshev 633 ## i.e., C(i,j) = T_{i-1}(P(j)), where T_{i-1} is the Chebyshev
634 ## polynomial of degree i-1. 634 ## polynomial of degree i-1.
635 ## CHEBVAND(M,P) is a rectangular version of CHEBVAND(P) with M rows. 635 ## CHEBVAND(M,P) is a rectangular version of CHEBVAND(P) with M rows.
636 ## Special case: If P is a scalar then P equally spaced points on 636 ## Special case: If P is a scalar then P equally spaced points on
637 ## [0,1] are used. 637 ## [0,1] are used.
638 ## 638 ##
639 ## Reference: 639 ## Reference:
640 ## N.J. Higham, Stability analysis of algorithms for solving confluent 640 ## N.J. Higham, Stability analysis of algorithms for solving confluent
641 ## Vandermonde-like systems, SIAM J. Matrix Anal. Appl., 11 (1990), 641 ## Vandermonde-like systems, SIAM J. Matrix Anal. Appl., 11 (1990),
642 ## pp. 23-41. 642 ## pp. 23-41.
643 643
644 if (nargin < 1 || nargin > 2) 644 if (nargin < 1 || nargin > 2)
645 error ("gallery: 1 or 2 arguments are required for chebvand matrix."); 645 error ("gallery: 1 or 2 arguments are required for chebvand matrix.");
646 endif 646 endif
647 647
678 endif 678 endif
679 endfunction 679 endfunction
680 680
681 function A = chow (n, alpha = 1, delta = 0) 681 function A = chow (n, alpha = 1, delta = 0)
682 ## CHOW Chow matrix - a singular Toeplitz lower Hessenberg matrix. 682 ## CHOW Chow matrix - a singular Toeplitz lower Hessenberg matrix.
683 ## A = CHOW(N, ALPHA, DELTA) is a Toeplitz lower Hessenberg matrix 683 ## A = CHOW(N, ALPHA, DELTA) is a Toeplitz lower Hessenberg matrix
684 ## A = H(ALPHA) + DELTA*EYE, where H(i,j) = ALPHA^(i-j+1). 684 ## A = H(ALPHA) + DELTA*EYE, where H(i,j) = ALPHA^(i-j+1).
685 ## H(ALPHA) has p = FLOOR(N/2) zero eigenvalues, the rest being 685 ## H(ALPHA) has p = FLOOR(N/2) zero eigenvalues, the rest being
686 ## 4*ALPHA*COS( k*PI/(N+2) )^2, k=1:N-p. 686 ## 4*ALPHA*COS( k*PI/(N+2) )^2, k=1:N-p.
687 ## Defaults: ALPHA = 1, DELTA = 0. 687 ## Defaults: ALPHA = 1, DELTA = 0.
688 ## 688 ##
689 ## References: 689 ## References:
690 ## T.S. Chow, A class of Hessenberg matrices with known 690 ## T.S. Chow, A class of Hessenberg matrices with known
691 ## eigenvalues and inverses, SIAM Review, 11 (1969), pp. 391-395. 691 ## eigenvalues and inverses, SIAM Review, 11 (1969), pp. 391-395.
692 ## G. Fairweather, On the eigenvalues and eigenvectors of a class of 692 ## G. Fairweather, On the eigenvalues and eigenvectors of a class of
693 ## Hessenberg matrices, SIAM Review, 13 (1971), pp. 220-221. 693 ## Hessenberg matrices, SIAM Review, 13 (1971), pp. 220-221.
694 694
695 if (nargin < 1 || nargin > 3) 695 if (nargin < 1 || nargin > 3)
696 error ("gallery: 1 to 3 arguments are required for chow matrix."); 696 error ("gallery: 1 to 3 arguments are required for chow matrix.");
697 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 697 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
698 error ("gallery: N must be an integer for chow matrix."); 698 error ("gallery: N must be an integer for chow matrix.");
705 A = toeplitz (alpha.^(1:n), [alpha 1 zeros(1, n-2)]) + delta * eye (n); 705 A = toeplitz (alpha.^(1:n), [alpha 1 zeros(1, n-2)]) + delta * eye (n);
706 endfunction 706 endfunction
707 707
708 function C = circul (v) 708 function C = circul (v)
709 ## CIRCUL Circulant matrix. 709 ## CIRCUL Circulant matrix.
710 ## C = CIRCUL(V) is the circulant matrix whose first row is V. 710 ## C = CIRCUL(V) is the circulant matrix whose first row is V.
711 ## (A circulant matrix has the property that each row is obtained 711 ## (A circulant matrix has the property that each row is obtained
712 ## from the previous one by cyclically permuting the entries one step 712 ## from the previous one by cyclically permuting the entries one step
713 ## forward; it is a special Toeplitz matrix in which the diagonals 713 ## forward; it is a special Toeplitz matrix in which the diagonals
714 ## `wrap round'.) 714 ## `wrap round'.)
715 ## Special case: if V is a scalar then C = CIRCUL(1:V). 715 ## Special case: if V is a scalar then C = CIRCUL(1:V).
716 ## The eigensystem of C (N-by-N) is known explicitly. If t is an Nth 716 ## The eigensystem of C (N-by-N) is known explicitly. If t is an Nth
717 ## root of unity, then the inner product of V with W = [1 t t^2 ... t^N] 717 ## root of unity, then the inner product of V with W = [1 t t^2 ... t^N]
718 ## is an eigenvalue of C, and W(N:-1:1) is an eigenvector of C. 718 ## is an eigenvalue of C, and W(N:-1:1) is an eigenvector of C.
719 ## 719 ##
720 ## Reference: 720 ## Reference:
721 ## P.J. Davis, Circulant Matrices, John Wiley, 1977. 721 ## P.J. Davis, Circulant Matrices, John Wiley, 1977.
722 722
723 if (nargin != 1) 723 if (nargin != 1)
724 error ("gallery: 1 argument is required for circul matrix."); 724 error ("gallery: 1 argument is required for circul matrix.");
725 elseif (! isnumeric (v)) 725 elseif (! isnumeric (v))
726 error ("gallery: V must be numeric for circul matrix."); 726 error ("gallery: V must be numeric for circul matrix.");
740 C = toeplitz ([v(1) v(n:-1:2)], v); 740 C = toeplitz ([v(1) v(n:-1:2)], v);
741 endfunction 741 endfunction
742 742
743 function A = clement (n, k = 0) 743 function A = clement (n, k = 0)
744 ## CLEMENT Clement matrix - tridiagonal with zero diagonal entries. 744 ## CLEMENT Clement matrix - tridiagonal with zero diagonal entries.
745 ## CLEMENT(N, K) is a tridiagonal matrix with zero diagonal entries 745 ## CLEMENT(N, K) is a tridiagonal matrix with zero diagonal entries
746 ## and known eigenvalues. It is singular if N is odd. About 64 746 ## and known eigenvalues. It is singular if N is odd. About 64
747 ## percent of the entries of the inverse are zero. The eigenvalues 747 ## percent of the entries of the inverse are zero. The eigenvalues
748 ## are plus and minus the numbers N-1, N-3, N-5, ..., (1 or 0). 748 ## are plus and minus the numbers N-1, N-3, N-5, ..., (1 or 0).
749 ## For K = 0 (the default) the matrix is unsymmetric, while for 749 ## For K = 0 (the default) the matrix is unsymmetric, while for
750 ## K = 1 it is symmetric. 750 ## K = 1 it is symmetric.
751 ## CLEMENT(N, 1) is diagonally similar to CLEMENT(N). 751 ## CLEMENT(N, 1) is diagonally similar to CLEMENT(N).
752 ## 752 ##
753 ## Similar properties hold for TRIDIAG(X,Y,Z) where Y = ZEROS(N,1). 753 ## Similar properties hold for TRIDIAG(X,Y,Z) where Y = ZEROS(N,1).
754 ## The eigenvalues still come in plus/minus pairs but they are not 754 ## The eigenvalues still come in plus/minus pairs but they are not
755 ## known explicitly. 755 ## known explicitly.
756 ## 756 ##
757 ## References: 757 ## References:
758 ## P.A. Clement, A class of triple-diagonal matrices for test 758 ## P.A. Clement, A class of triple-diagonal matrices for test
759 ## purposes, SIAM Review, 1 (1959), pp. 50-52. 759 ## purposes, SIAM Review, 1 (1959), pp. 50-52.
760 ## A. Edelman and E. Kostlan, The road from Kac's matrix to Kac's 760 ## A. Edelman and E. Kostlan, The road from Kac's matrix to Kac's
761 ## random polynomials. In John~G. Lewis, editor, Proceedings of 761 ## random polynomials. In John~G. Lewis, editor, Proceedings of
762 ## the Fifth SIAM Conference on Applied Linear Algebra Society 762 ## the Fifth SIAM Conference on Applied Linear Algebra Society
763 ## for Industrial and Applied Mathematics, Philadelphia, 1994, 763 ## for Industrial and Applied Mathematics, Philadelphia, 1994,
764 ## pp. 503-507. 764 ## pp. 503-507.
765 ## O. Taussky and J. Todd, Another look at a matrix of Mark Kac, 765 ## O. Taussky and J. Todd, Another look at a matrix of Mark Kac,
766 ## Linear Algebra and Appl., 150 (1991), pp. 341-360. 766 ## Linear Algebra and Appl., 150 (1991), pp. 341-360.
767 767
768 if (nargin < 1 || nargin > 2) 768 if (nargin < 1 || nargin > 2)
769 error ("gallery: 1 or 2 arguments are required for clement matrix."); 769 error ("gallery: 1 or 2 arguments are required for clement matrix.");
770 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 770 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
771 error ("gallery: N must be an integer for clement matrix."); 771 error ("gallery: N must be an integer for clement matrix.");
787 endif 787 endif
788 endfunction 788 endfunction
789 789
790 function C = compar (A, k = 0) 790 function C = compar (A, k = 0)
791 ## COMP Comparison matrices. 791 ## COMP Comparison matrices.
792 ## COMP(A) is DIAG(B) - TRIL(B,-1) - TRIU(B,1), where B = ABS(A). 792 ## COMP(A) is DIAG(B) - TRIL(B,-1) - TRIU(B,1), where B = ABS(A).
793 ## COMP(A, 1) is A with each diagonal element replaced by its 793 ## COMP(A, 1) is A with each diagonal element replaced by its
794 ## absolute value, and each off-diagonal element replaced by minus 794 ## absolute value, and each off-diagonal element replaced by minus
795 ## the absolute value of the largest element in absolute value in 795 ## the absolute value of the largest element in absolute value in
796 ## its row. However, if A is triangular COMP(A, 1) is too. 796 ## its row. However, if A is triangular COMP(A, 1) is too.
797 ## COMP(A, 0) is the same as COMP(A). 797 ## COMP(A, 0) is the same as COMP(A).
798 ## COMP(A) is often denoted by M(A) in the literature. 798 ## COMP(A) is often denoted by M(A) in the literature.
799 ## 799 ##
800 ## Reference (e.g.): 800 ## Reference (e.g.):
801 ## N.J. Higham, A survey of condition number estimation for 801 ## N.J. Higham, A survey of condition number estimation for
802 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. 802 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596.
803 803
804 if (nargin < 1 || nargin > 2) 804 if (nargin < 1 || nargin > 2)
805 error ("gallery: 1 or 2 arguments are required for compar matrix."); 805 error ("gallery: 1 or 2 arguments are required for compar matrix.");
806 elseif (! isnumeric (A) || ndims (A) != 2) 806 elseif (! isnumeric (A) || ndims (A) != 2)
807 error ("gallery: A must be a 2-D matrix for compar matrix."); 807 error ("gallery: A must be a 2-D matrix for compar matrix.");
839 839
840 endfunction 840 endfunction
841 841
842 function A = condex (n, k = 4, theta = 100) 842 function A = condex (n, k = 4, theta = 100)
843 ## CONDEX `Counterexamples' to matrix condition number estimators. 843 ## CONDEX `Counterexamples' to matrix condition number estimators.
844 ## CONDEX(N, K, THETA) is a `counterexample' matrix to a condition 844 ## CONDEX(N, K, THETA) is a `counterexample' matrix to a condition
845 ## estimator. It has order N and scalar parameter THETA (default 100). 845 ## estimator. It has order N and scalar parameter THETA (default 100).
846 ## If N is not equal to the `natural' size of the matrix then 846 ## If N is not equal to the `natural' size of the matrix then
847 ## the matrix is padded out with an identity matrix to order N. 847 ## the matrix is padded out with an identity matrix to order N.
848 ## The matrix, its natural size, and the estimator to which it applies 848 ## The matrix, its natural size, and the estimator to which it applies
849 ## are specified by K (default K = 4) as follows: 849 ## are specified by K (default K = 4) as follows:
850 ## K = 1: 4-by-4, LINPACK (RCOND) 850 ## K = 1: 4-by-4, LINPACK (RCOND)
851 ## K = 2: 3-by-3, LINPACK (RCOND) 851 ## K = 2: 3-by-3, LINPACK (RCOND)
852 ## K = 3: arbitrary, LINPACK (RCOND) (independent of THETA) 852 ## K = 3: arbitrary, LINPACK (RCOND) (independent of THETA)
853 ## K = 4: N >= 4, SONEST (Higham 1988) 853 ## K = 4: N >= 4, SONEST (Higham 1988)
854 ## (Note that in practice the K = 4 matrix is not usually a 854 ## (Note that in practice the K = 4 matrix is not usually a
855 ## counterexample because of the rounding errors in forming it.) 855 ## counterexample because of the rounding errors in forming it.)
856 ## 856 ##
857 ## References: 857 ## References:
858 ## A.K. Cline and R.K. Rew, A set of counter-examples to three 858 ## A.K. Cline and R.K. Rew, A set of counter-examples to three
859 ## condition number estimators, SIAM J. Sci. Stat. Comput., 859 ## condition number estimators, SIAM J. Sci. Stat. Comput.,
860 ## 4 (1983), pp. 602-611. 860 ## 4 (1983), pp. 602-611.
861 ## N.J. Higham, FORTRAN codes for estimating the one-norm of a real or 861 ## N.J. Higham, FORTRAN codes for estimating the one-norm of a real or
862 ## complex matrix, with applications to condition estimation 862 ## complex matrix, with applications to condition estimation
863 ## (Algorithm 674), ACM Trans. Math. Soft., 14 (1988), pp. 381-396. 863 ## (Algorithm 674), ACM Trans. Math. Soft., 14 (1988), pp. 381-396.
864 864
865 if (nargin < 1 || nargin > 3) 865 if (nargin < 1 || nargin > 3)
866 error ("gallery: 1 to 3 arguments are required for condex matrix."); 866 error ("gallery: 1 to 3 arguments are required for condex matrix.");
867 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 867 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
868 error ("gallery: N must be an integer for condex matrix."); 868 error ("gallery: N must be an integer for condex matrix.");
911 endif 911 endif
912 endfunction 912 endfunction
913 913
914 function A = cycol (n, k) 914 function A = cycol (n, k)
915 ## CYCOL Matrix whose columns repeat cyclically. 915 ## CYCOL Matrix whose columns repeat cyclically.
916 ## A = CYCOL([M N], K) is an M-by-N matrix of the form A = B(1:M,1:N) 916 ## A = CYCOL([M N], K) is an M-by-N matrix of the form A = B(1:M,1:N)
917 ## where B = [C C C...] and C = RANDN(M, K). Thus A's columns repeat 917 ## where B = [C C C...] and C = RANDN(M, K). Thus A's columns repeat
918 ## cyclically, and A has rank at most K. K need not divide N. 918 ## cyclically, and A has rank at most K. K need not divide N.
919 ## K defaults to ROUND(N/4). 919 ## K defaults to ROUND(N/4).
920 ## CYCOL(N, K), where N is a scalar, is the same as CYCOL([N N], K). 920 ## CYCOL(N, K), where N is a scalar, is the same as CYCOL([N N], K).
921 ## 921 ##
922 ## This type of matrix can lead to underflow problems for Gaussian 922 ## This type of matrix can lead to underflow problems for Gaussian
923 ## elimination: see NA Digest Volume 89, Issue 3 (January 22, 1989). 923 ## elimination: see NA Digest Volume 89, Issue 3 (January 22, 1989).
924 924
925 if (nargin < 1 || nargin > 2) 925 if (nargin < 1 || nargin > 2)
926 error ("gallery: 1 or 2 arguments are required for cycol matrix."); 926 error ("gallery: 1 or 2 arguments are required for cycol matrix.");
927 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) 927 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n)
928 error ("gallery: N must be a 1 or 2 element integer for cycol matrix."); 928 error ("gallery: N must be a 1 or 2 element integer for cycol matrix.");
945 A = A(:,1:n); 945 A = A(:,1:n);
946 endfunction 946 endfunction
947 947
948 function [c, d, e] = dorr (n, theta = 0.01) 948 function [c, d, e] = dorr (n, theta = 0.01)
949 ## DORR Dorr matrix - diagonally dominant, ill conditioned, tridiagonal. 949 ## DORR Dorr matrix - diagonally dominant, ill conditioned, tridiagonal.
950 ## [C, D, E] = DORR(N, THETA) returns the vectors defining a row diagonally 950 ## [C, D, E] = DORR(N, THETA) returns the vectors defining a row diagonally
951 ## dominant, tridiagonal M-matrix that is ill conditioned for small 951 ## dominant, tridiagonal M-matrix that is ill conditioned for small
952 ## values of the parameter THETA >= 0. 952 ## values of the parameter THETA >= 0.
953 ## If only one output parameter is supplied then 953 ## If only one output parameter is supplied then
954 ## C = FULL(TRIDIAG(C,D,E)), i.e., the matrix iself is returned. 954 ## C = FULL(TRIDIAG(C,D,E)), i.e., the matrix iself is returned.
955 ## The columns of INV(C) vary greatly in norm. THETA defaults to 0.01. 955 ## The columns of INV(C) vary greatly in norm. THETA defaults to 0.01.
956 ## The amount of diagonal dominance is given by (ignoring rounding errors): 956 ## The amount of diagonal dominance is given by (ignoring rounding errors):
957 ## COMP(C)*ONES(N,1) = THETA*(N+1)^2 * [1 0 0 ... 0 1]'. 957 ## COMP(C)*ONES(N,1) = THETA*(N+1)^2 * [1 0 0 ... 0 1]'.
958 ## 958 ##
959 ## Reference: 959 ## Reference:
960 ## F.W. Dorr, An example of ill-conditioning in the numerical 960 ## F.W. Dorr, An example of ill-conditioning in the numerical
961 ## solution of singular perturbation problems, Math. Comp., 25 (1971), 961 ## solution of singular perturbation problems, Math. Comp., 25 (1971),
962 ## pp. 271-283. 962 ## pp. 271-283.
963 963
964 if (nargin < 1 || nargin > 2) 964 if (nargin < 1 || nargin > 2)
965 error ("gallery: 1 or 2 arguments are required for dorr matrix."); 965 error ("gallery: 1 or 2 arguments are required for dorr matrix.");
966 elseif (! isscalar (n) || ! isnumeric (n) || fix (n) != n) 966 elseif (! isscalar (n) || ! isnumeric (n) || fix (n) != n)
967 error ("gallery: N must be an integer for dorr matrix."); 967 error ("gallery: N must be an integer for dorr matrix.");
996 endif 996 endif
997 endfunction 997 endfunction
998 998
999 function A = dramadah (n, k = 1) 999 function A = dramadah (n, k = 1)
1000 ## DRAMADAH A (0,1) matrix whose inverse has large integer entries. 1000 ## DRAMADAH A (0,1) matrix whose inverse has large integer entries.
1001 ## An anti-Hadamard matrix A is a matrix with elements 0 or 1 for 1001 ## An anti-Hadamard matrix A is a matrix with elements 0 or 1 for
1002 ## which MU(A) := NORM(INV(A),'FRO') is maximal. 1002 ## which MU(A) := NORM(INV(A),'FRO') is maximal.
1003 ## A = DRAMADAH(N, K) is an N-by-N (0,1) matrix for which MU(A) is 1003 ## A = DRAMADAH(N, K) is an N-by-N (0,1) matrix for which MU(A) is
1004 ## relatively large, although not necessarily maximal. 1004 ## relatively large, although not necessarily maximal.
1005 ## Available types (the default is K = 1): 1005 ## Available types (the default is K = 1):
1006 ## K = 1: A is Toeplitz, with ABS(DET(A)) = 1, and MU(A) > c(1.75)^N, 1006 ## K = 1: A is Toeplitz, with ABS(DET(A)) = 1, and MU(A) > c(1.75)^N,
1007 ## where c is a constant. 1007 ## where c is a constant.
1008 ## K = 2: A is upper triangular and Toeplitz. 1008 ## K = 2: A is upper triangular and Toeplitz.
1009 ## The inverses of both types have integer entries. 1009 ## The inverses of both types have integer entries.
1010 ## 1010 ##
1011 ## Another interesting (0,1) matrix: 1011 ## Another interesting (0,1) matrix:
1012 ## K = 3: A has maximal determinant among (0,1) lower Hessenberg 1012 ## K = 3: A has maximal determinant among (0,1) lower Hessenberg
1013 ## matrices: det(A) = the n'th Fibonacci number. A is Toeplitz. 1013 ## matrices: det(A) = the n'th Fibonacci number. A is Toeplitz.
1014 ## The eigenvalues have an interesting distribution in the complex 1014 ## The eigenvalues have an interesting distribution in the complex
1015 ## plane. 1015 ## plane.
1016 ## 1016 ##
1017 ## References: 1017 ## References:
1018 ## R.L. Graham and N.J.A. Sloane, Anti-Hadamard matrices, 1018 ## R.L. Graham and N.J.A. Sloane, Anti-Hadamard matrices,
1019 ## Linear Algebra and Appl., 62 (1984), pp. 113-137. 1019 ## Linear Algebra and Appl., 62 (1984), pp. 113-137.
1020 ## L. Ching, The maximum determinant of an nxn lower Hessenberg 1020 ## L. Ching, The maximum determinant of an nxn lower Hessenberg
1021 ## (0,1) matrix, Linear Algebra and Appl., 183 (1993), pp. 147-153. 1021 ## (0,1) matrix, Linear Algebra and Appl., 183 (1993), pp. 147-153.
1022 1022
1023 if (nargin < 1 || nargin > 2) 1023 if (nargin < 1 || nargin > 2)
1024 error ("gallery: 1 to 2 arguments are required for dramadah matrix."); 1024 error ("gallery: 1 to 2 arguments are required for dramadah matrix.");
1025 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1025 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1026 error ("gallery: N must be an integer for dramadah matrix."); 1026 error ("gallery: N must be an integer for dramadah matrix.");
1063 endswitch 1063 endswitch
1064 endfunction 1064 endfunction
1065 1065
1066 function A = fiedler (c) 1066 function A = fiedler (c)
1067 ## FIEDLER Fiedler matrix - symmetric. 1067 ## FIEDLER Fiedler matrix - symmetric.
1068 ## A = FIEDLER(C), where C is an n-vector, is the n-by-n symmetric 1068 ## FIEDLER(C), where C is an n-vector, is the n-by-n symmetric
1069 ## matrix with elements ABS(C(i)-C(j)). 1069 ## matrix with elements ABS(C(i)-C(j)).
1070 ## Special case: if C is a scalar, then A = FIEDLER(1:C) 1070 ## Special case: if C is a scalar, then A = FIEDLER(1:C)
1071 ## (i.e. A(i,j) = ABS(i-j)). 1071 ## (i.e. A(i,j) = ABS(i-j)).
1072 ## Properties: 1072 ## Properties:
1073 ## FIEDLER(N) has a dominant positive eigenvalue and all the other 1073 ## FIEDLER(N) has a dominant positive eigenvalue and all the other
1074 ## eigenvalues are negative (Szego, 1936). 1074 ## eigenvalues are negative (Szego, 1936).
1075 ## Explicit formulas for INV(A) and DET(A) are given by Todd (1977) 1075 ## Explicit formulas for INV(A) and DET(A) are given by Todd (1977)
1076 ## and attributed to Fiedler. These indicate that INV(A) is 1076 ## and attributed to Fiedler. These indicate that INV(A) is
1077 ## tridiagonal except for nonzero (1,n) and (n,1) elements. 1077 ## tridiagonal except for nonzero (1,n) and (n,1) elements.
1078 ## [I think these formulas are valid only if the elements of 1078 ## [I think these formulas are valid only if the elements of
1079 ## C are in increasing or decreasing order---NJH.] 1079 ## C are in increasing or decreasing order---NJH.]
1080 ## 1080 ##
1081 ## References: 1081 ## References:
1082 ## G. Szego, Solution to problem 3705, Amer. Math. Monthly, 1082 ## G. Szego, Solution to problem 3705, Amer. Math. Monthly,
1083 ## 43 (1936), pp. 246-259. 1083 ## 43 (1936), pp. 246-259.
1084 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, 1084 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra,
1085 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 159. 1085 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 159.
1086 1086
1087 if (nargin != 1) 1087 if (nargin != 1)
1088 error ("gallery: 1 argument is required for fiedler matrix."); 1088 error ("gallery: 1 argument is required for fiedler matrix.");
1089 elseif (! isnumeric (c)) 1089 elseif (! isnumeric (c))
1090 error ("gallery: C must be numeric for fiedler matrix."); 1090 error ("gallery: C must be numeric for fiedler matrix.");
1105 A = abs (A - A.'); # NB. array transpose. 1105 A = abs (A - A.'); # NB. array transpose.
1106 endfunction 1106 endfunction
1107 1107
1108 function A = forsythe (n, alpha = sqrt (eps), lambda = 0) 1108 function A = forsythe (n, alpha = sqrt (eps), lambda = 0)
1109 ## FORSYTHE Forsythe matrix - a perturbed Jordan block. 1109 ## FORSYTHE Forsythe matrix - a perturbed Jordan block.
1110 ## FORSYTHE(N, ALPHA, LAMBDA) is the N-by-N matrix equal to 1110 ## FORSYTHE(N, ALPHA, LAMBDA) is the N-by-N matrix equal to
1111 ## JORDBLOC(N, LAMBDA) except it has an ALPHA in the (N,1) position. 1111 ## JORDBLOC(N, LAMBDA) except it has an ALPHA in the (N,1) position.
1112 ## It has the characteristic polynomial 1112 ## It has the characteristic polynomial
1113 ## DET(A-t*EYE) = (LAMBDA-t)^N - (-1)^N ALPHA. 1113 ## DET(A-t*EYE) = (LAMBDA-t)^N - (-1)^N ALPHA.
1114 ## ALPHA defaults to SQRT(EPS) and LAMBDA to 0. 1114 ## ALPHA defaults to SQRT(EPS) and LAMBDA to 0.
1115 1115
1116 if (nargin < 1 || nargin > 3) 1116 if (nargin < 1 || nargin > 3)
1117 error ("gallery: 1 to 3 arguments are required for forsythe matrix."); 1117 error ("gallery: 1 to 3 arguments are required for forsythe matrix.");
1118 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1118 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1119 error ("gallery: N must be an integer for forsythe matrix."); 1119 error ("gallery: N must be an integer for forsythe matrix.");
1127 A(n,1) = alpha; 1127 A(n,1) = alpha;
1128 endfunction 1128 endfunction
1129 1129
1130 function F = frank (n, k = 0) 1130 function F = frank (n, k = 0)
1131 ## FRANK Frank matrix---ill conditioned eigenvalues. 1131 ## FRANK Frank matrix---ill conditioned eigenvalues.
1132 ## F = FRANK(N, K) is the Frank matrix of order N. It is upper 1132 ## F = FRANK(N, K) is the Frank matrix of order N. It is upper
1133 ## Hessenberg with determinant 1. K = 0 is the default; if K = 1 the 1133 ## Hessenberg with determinant 1. K = 0 is the default; if K = 1 the
1134 ## elements are reflected about the anti-diagonal (1,N)--(N,1). 1134 ## elements are reflected about the anti-diagonal (1,N)--(N,1).
1135 ## F has all positive eigenvalues and they occur in reciprocal pairs 1135 ## F has all positive eigenvalues and they occur in reciprocal pairs
1136 ## (so that 1 is an eigenvalue if N is odd). 1136 ## (so that 1 is an eigenvalue if N is odd).
1137 ## The eigenvalues of F may be obtained in terms of the zeros of the 1137 ## The eigenvalues of F may be obtained in terms of the zeros of the
1138 ## Hermite polynomials. 1138 ## Hermite polynomials.
1139 ## The FLOOR(N/2) smallest eigenvalues of F are ill conditioned, 1139 ## The FLOOR(N/2) smallest eigenvalues of F are ill conditioned,
1140 ## the more so for bigger N. 1140 ## the more so for bigger N.
1141 ## 1141 ##
1142 ## DET(FRANK(N)') comes out far from 1 for large N---see Frank (1958) 1142 ## DET(FRANK(N)') comes out far from 1 for large N---see Frank (1958)
1143 ## and Wilkinson (1960) for discussions. 1143 ## and Wilkinson (1960) for discussions.
1144 ## 1144 ##
1145 ## This version incorporates improvements suggested by W. Kahan. 1145 ## This version incorporates improvements suggested by W. Kahan.
1146 ## 1146 ##
1147 ## References: 1147 ## References:
1148 ## W.L. Frank, Computing eigenvalues of complex matrices by determinant 1148 ## W.L. Frank, Computing eigenvalues of complex matrices by determinant
1149 ## evaluation and by methods of Danilewski and Wielandt, J. Soc. 1149 ## evaluation and by methods of Danilewski and Wielandt, J. Soc.
1150 ## Indust. Appl. Math., 6 (1958), pp. 378-392 (see pp. 385, 388). 1150 ## Indust. Appl. Math., 6 (1958), pp. 378-392 (see pp. 385, 388).
1151 ## G.H. Golub and J.H. Wilkinson, Ill-conditioned eigensystems and the 1151 ## G.H. Golub and J.H. Wilkinson, Ill-conditioned eigensystems and the
1152 ## computation of the Jordan canonical form, SIAM Review, 18 (1976), 1152 ## computation of the Jordan canonical form, SIAM Review, 18 (1976),
1153 ## pp. 578-619 (Section 13). 1153 ## pp. 578-619 (Section 13).
1154 ## H. Rutishauser, On test matrices, Programmation en Mathematiques 1154 ## H. Rutishauser, On test matrices, Programmation en Mathematiques
1155 ## Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165, 1155 ## Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165,
1156 ## 1966, pp. 349-365. Section 9. 1156 ## 1966, pp. 349-365. Section 9.
1157 ## J.H. Wilkinson, Error analysis of floating-point computation, 1157 ## J.H. Wilkinson, Error analysis of floating-point computation,
1158 ## Numer. Math., 2 (1960), pp. 319-340 (Section 8). 1158 ## Numer. Math., 2 (1960), pp. 319-340 (Section 8).
1159 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University 1159 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University
1160 ## Press, 1965 (pp. 92-93). 1160 ## Press, 1965 (pp. 92-93).
1161 ## The next two references give details of the eigensystem, as does 1161 ## The next two references give details of the eigensystem, as does
1162 ## Rutishauser (see above). 1162 ## Rutishauser (see above).
1163 ## P.J. Eberlein, A note on the matrices denoted by B_n, SIAM J. Appl. 1163 ## P.J. Eberlein, A note on the matrices denoted by B_n, SIAM J. Appl.
1164 ## Math., 20 (1971), pp. 87-92. 1164 ## Math., 20 (1971), pp. 87-92.
1165 ## J.M. Varah, A generalization of the Frank matrix, SIAM J. Sci. Stat. 1165 ## J.M. Varah, A generalization of the Frank matrix, SIAM J. Sci. Stat.
1166 ## Comput., 7 (1986), pp. 835-839. 1166 ## Comput., 7 (1986), pp. 835-839.
1167 1167
1168 if (nargin < 1 || nargin > 2) 1168 if (nargin < 1 || nargin > 2)
1169 error ("gallery: 1 to 2 arguments are required for frank matrix."); 1169 error ("gallery: 1 to 2 arguments are required for frank matrix.");
1170 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1170 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1171 error ("gallery: N must be an integer for frank matrix."); 1171 error ("gallery: N must be an integer for frank matrix.");
1194 endfunction 1194 endfunction
1195 1195
1196 function A = gearmat (n, i = n, j = -n) 1196 function A = gearmat (n, i = n, j = -n)
1197 ## NOTE: this function was named gearm in the original Test Matrix Toolbox 1197 ## NOTE: this function was named gearm in the original Test Matrix Toolbox
1198 ## GEARMAT Gear matrix. 1198 ## GEARMAT Gear matrix.
1199 ## A = GEARMAT(N,I,J) is the N-by-N matrix with ones on the sub- and 1199 ## A = GEARMAT(N,I,J) is the N-by-N matrix with ones on the sub- and
1200 ## super-diagonals, SIGN(I) in the (1,ABS(I)) position, SIGN(J) 1200 ## super-diagonals, SIGN(I) in the (1,ABS(I)) position, SIGN(J)
1201 ## in the (N,N+1-ABS(J)) position, and zeros everywhere else. 1201 ## in the (N,N+1-ABS(J)) position, and zeros everywhere else.
1202 ## Defaults: I = N, j = -N. 1202 ## Defaults: I = N, j = -N.
1203 ## All eigenvalues are of the form 2*COS(a) and the eigenvectors 1203 ## All eigenvalues are of the form 2*COS(a) and the eigenvectors
1204 ## are of the form [SIN(w+a), SIN(w+2a), ..., SIN(w+Na)]. 1204 ## are of the form [SIN(w+a), SIN(w+2a), ..., SIN(w+Na)].
1205 ## The values of a and w are given in the reference below. 1205 ## The values of a and w are given in the reference below.
1206 ## A can have double and triple eigenvalues and can be defective. 1206 ## A can have double and triple eigenvalues and can be defective.
1207 ## GEARMAT(N) is singular. 1207 ## GEARMAT(N) is singular.
1208 ## 1208 ##
1209 ## (GEAR is a Simulink function, hence GEARMAT for Gear matrix.) 1209 ## (GEAR is a Simulink function, hence GEARMAT for Gear matrix.)
1210 ## Reference: 1210 ## Reference:
1211 ## C.W. Gear, A simple set of test matrices for eigenvalue programs, 1211 ## C.W. Gear, A simple set of test matrices for eigenvalue programs,
1212 ## Math. Comp., 23 (1969), pp. 119-125. 1212 ## Math. Comp., 23 (1969), pp. 119-125.
1213 1213
1214 if (nargin < 1 || nargin > 3) 1214 if (nargin < 1 || nargin > 3)
1215 error ("gallery: 1 to 3 arguments are required for gearmat matrix."); 1215 error ("gallery: 1 to 3 arguments are required for gearmat matrix.");
1216 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1216 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1217 error ("gallery: N must be an integer for gearmat matrix."); 1217 error ("gallery: N must be an integer for gearmat matrix.");
1226 A(n, n+1 - abs (j)) = sign (j); 1226 A(n, n+1 - abs (j)) = sign (j);
1227 endfunction 1227 endfunction
1228 1228
1229 function G = grcar (n, k = 3) 1229 function G = grcar (n, k = 3)
1230 ## GRCAR Grcar matrix - a Toeplitz matrix with sensitive eigenvalues. 1230 ## GRCAR Grcar matrix - a Toeplitz matrix with sensitive eigenvalues.
1231 ## GRCAR(N, K) is an N-by-N matrix with -1s on the 1231 ## GRCAR(N, K) is an N-by-N matrix with -1s on the
1232 ## subdiagonal, 1s on the diagonal, and K superdiagonals of 1s. 1232 ## subdiagonal, 1s on the diagonal, and K superdiagonals of 1s.
1233 ## The default is K = 3. The eigenvalues of this matrix form an 1233 ## The default is K = 3. The eigenvalues of this matrix form an
1234 ## interesting pattern in the complex plane (try PS(GRCAR(32))). 1234 ## interesting pattern in the complex plane (try PS(GRCAR(32))).
1235 ## 1235 ##
1236 ## References: 1236 ## References:
1237 ## J.F. Grcar, Operator coefficient methods for linear equations, 1237 ## J.F. Grcar, Operator coefficient methods for linear equations,
1238 ## Report SAND89-8691, Sandia National Laboratories, Albuquerque, 1238 ## Report SAND89-8691, Sandia National Laboratories, Albuquerque,
1239 ## New Mexico, 1989 (Appendix 2). 1239 ## New Mexico, 1989 (Appendix 2).
1240 ## N.M. Nachtigal, L. Reichel and L.N. Trefethen, A hybrid GMRES 1240 ## N.M. Nachtigal, L. Reichel and L.N. Trefethen, A hybrid GMRES
1241 ## algorithm for nonsymmetric linear systems, SIAM J. Matrix Anal. 1241 ## algorithm for nonsymmetric linear systems, SIAM J. Matrix Anal.
1242 ## Appl., 13 (1992), pp. 796-825. 1242 ## Appl., 13 (1992), pp. 796-825.
1243 1243
1244 if (nargin < 1 || nargin > 2) 1244 if (nargin < 1 || nargin > 2)
1245 error ("gallery: 1 to 2 arguments are required for grcar matrix."); 1245 error ("gallery: 1 to 2 arguments are required for grcar matrix.");
1246 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1246 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1247 error ("gallery: N must be an integer for grcar matrix."); 1247 error ("gallery: N must be an integer for grcar matrix.");
1252 G = tril (triu (ones (n)), k) - diag (ones (n-1, 1), -1); 1252 G = tril (triu (ones (n)), k) - diag (ones (n-1, 1), -1);
1253 endfunction 1253 endfunction
1254 1254
1255 function A = hanowa (n, d = -1) 1255 function A = hanowa (n, d = -1)
1256 ## HANOWA A matrix whose eigenvalues lie on a vertical line in the complex plane. 1256 ## HANOWA A matrix whose eigenvalues lie on a vertical line in the complex plane.
1257 ## HANOWA(N, d) is the N-by-N block 2x2 matrix (thus N = 2M must be even) 1257 ## HANOWA(N, d) is the N-by-N block 2x2 matrix (thus N = 2M must be even)
1258 ## [d*EYE(M) -DIAG(1:M) 1258 ## [d*EYE(M) -DIAG(1:M)
1259 ## DIAG(1:M) d*EYE(M)] 1259 ## DIAG(1:M) d*EYE(M)]
1260 ## It has complex eigenvalues lambda(k) = d +/- k*i (1 <= k <= M). 1260 ## It has complex eigenvalues lambda(k) = d +/- k*i (1 <= k <= M).
1261 ## Parameter d defaults to -1. 1261 ## Parameter d defaults to -1.
1262 ## 1262 ##
1263 ## Reference: 1263 ## Reference:
1264 ## E. Hairer, S.P. Norsett and G. Wanner, Solving Ordinary 1264 ## E. Hairer, S.P. Norsett and G. Wanner, Solving Ordinary
1265 ## Differential Equations I: Nonstiff Problems, Springer-Verlag, 1265 ## Differential Equations I: Nonstiff Problems, Springer-Verlag,
1266 ## Berlin, 1987. (pp. 86-87) 1266 ## Berlin, 1987. (pp. 86-87)
1267 1267
1268 if (nargin < 1 || nargin > 2) 1268 if (nargin < 1 || nargin > 2)
1269 error ("gallery: 1 to 2 arguments are required for hanowa matrix."); 1269 error ("gallery: 1 to 2 arguments are required for hanowa matrix.");
1270 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1270 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1271 error ("gallery: N must be an integer for hanowa matrix."); 1271 error ("gallery: N must be an integer for hanowa matrix.");
1280 diag(1:m) d*eye(m) ]; 1280 diag(1:m) d*eye(m) ];
1281 endfunction 1281 endfunction
1282 1282
1283 function [v, beta] = house (x) 1283 function [v, beta] = house (x)
1284 ## HOUSE Householder matrix. 1284 ## HOUSE Householder matrix.
1285 ## If [v, beta] = HOUSE(x) then H = EYE - beta*v*v' is a Householder 1285 ## If [v, beta] = HOUSE(x) then H = EYE - beta*v*v' is a Householder
1286 ## matrix such that Hx = -sign(x(1))*norm(x)*e_1. 1286 ## matrix such that Hx = -sign(x(1))*norm(x)*e_1.
1287 ## NB: If x = 0 then v = 0, beta = 1 is returned. 1287 ## NB: If x = 0 then v = 0, beta = 1 is returned.
1288 ## x can be real or complex. 1288 ## x can be real or complex.
1289 ## sign(x) := exp(i*arg(x)) ( = x./abs(x) when x ~= 0). 1289 ## sign(x) := exp(i*arg(x)) ( = x./abs(x) when x ~= 0).
1290 ## 1290 ##
1291 ## Theory: (textbook references Golub & Van Loan 1989, 38-43; 1291 ## Theory: (textbook references Golub & Van Loan 1989, 38-43;
1292 ## Stewart 1973, 231-234, 262; Wilkinson 1965, 48-50). 1292 ## Stewart 1973, 231-234, 262; Wilkinson 1965, 48-50).
1293 ## Hx = y: (I - beta*v*v')x = -s*e_1. 1293 ## Hx = y: (I - beta*v*v')x = -s*e_1.
1294 ## Must have |s| = norm(x), v = x+s*e_1, and 1294 ## Must have |s| = norm(x), v = x+s*e_1, and
1295 ## x'y = x'Hx =(x'Hx)' real => arg(s) = arg(x(1)). 1295 ## x'y = x'Hx =(x'Hx)' real => arg(s) = arg(x(1)).
1296 ## So take s = sign(x(1))*norm(x) (which avoids cancellation). 1296 ## So take s = sign(x(1))*norm(x) (which avoids cancellation).
1297 ## v'v = (x(1)+s)^2 + x(2)^2 + ... + x(n)^2 1297 ## v'v = (x(1)+s)^2 + x(2)^2 + ... + x(n)^2
1298 ## = 2*norm(x)*(norm(x) + |x(1)|). 1298 ## = 2*norm(x)*(norm(x) + |x(1)|).
1299 ## 1299 ##
1300 ## References: 1300 ## References:
1301 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, 1301 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
1302 ## Johns Hopkins University Press, Baltimore, Maryland, 1989. 1302 ## Johns Hopkins University Press, Baltimore, Maryland, 1989.
1303 ## G.W. Stewart, Introduction to Matrix Computations, Academic Press, 1303 ## G.W. Stewart, Introduction to Matrix Computations, Academic Press,
1304 ## New York, 1973, 1304 ## New York, 1973,
1305 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University 1305 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University
1306 ## Press, 1965. 1306 ## Press, 1965.
1307 1307
1308 if (nargin != 1) 1308 if (nargin != 1)
1309 error ("gallery: 1 argument is required for house matrix."); 1309 error ("gallery: 1 argument is required for house matrix.");
1310 elseif (! isnumeric (x) || ! isvector (x) || numel (x) <= 1) 1310 elseif (! isnumeric (x) || ! isvector (x) || numel (x) <= 1)
1311 error ("gallery: X must be a vector for house matrix."); 1311 error ("gallery: X must be a vector for house matrix.");
1369 1369
1370 endfunction 1370 endfunction
1371 1371
1372 function A = invhess (x, y) 1372 function A = invhess (x, y)
1373 ## INVHESS Inverse of an upper Hessenberg matrix. 1373 ## INVHESS Inverse of an upper Hessenberg matrix.
1374 ## INVHESS(X, Y), where X is an N-vector and Y an N-1 vector, 1374 ## INVHESS(X, Y), where X is an N-vector and Y an N-1 vector,
1375 ## is the matrix whose lower triangle agrees with that of 1375 ## is the matrix whose lower triangle agrees with that of
1376 ## ONES(N,1)*X' and whose strict upper triangle agrees with 1376 ## ONES(N,1)*X' and whose strict upper triangle agrees with
1377 ## that of [1 Y]*ONES(1,N). 1377 ## that of [1 Y]*ONES(1,N).
1378 ## The matrix is nonsingular if X(1) ~= 0 and X(i+1) ~= Y(i) 1378 ## The matrix is nonsingular if X(1) ~= 0 and X(i+1) ~= Y(i)
1379 ## for all i, and its inverse is an upper Hessenberg matrix. 1379 ## for all i, and its inverse is an upper Hessenberg matrix.
1380 ## If Y is omitted it defaults to -X(1:N-1). 1380 ## If Y is omitted it defaults to -X(1:N-1).
1381 ## Special case: if X is a scalar INVHESS(X) is the same as 1381 ## Special case: if X is a scalar INVHESS(X) is the same as
1382 ## INVHESS(1:X). 1382 ## INVHESS(1:X).
1383 ## 1383 ##
1384 ## References: 1384 ## References:
1385 ## F.N. Valvi and V.S. Geroyannis, Analytic inverses and 1385 ## F.N. Valvi and V.S. Geroyannis, Analytic inverses and
1386 ## determinants for a class of matrices, IMA Journal of Numerical 1386 ## determinants for a class of matrices, IMA Journal of Numerical
1387 ## Analysis, 7 (1987), pp. 123-128. 1387 ## Analysis, 7 (1987), pp. 123-128.
1388 ## W.-L. Cao and W.J. Stewart, A note on inverses of Hessenberg-like 1388 ## W.-L. Cao and W.J. Stewart, A note on inverses of Hessenberg-like
1389 ## matrices, Linear Algebra and Appl., 76 (1986), pp. 233-240. 1389 ## matrices, Linear Algebra and Appl., 76 (1986), pp. 233-240.
1390 ## Y. Ikebe, On inverses of Hessenberg matrices, Linear Algebra and 1390 ## Y. Ikebe, On inverses of Hessenberg matrices, Linear Algebra and
1391 ## Appl., 24 (1979), pp. 93-97. 1391 ## Appl., 24 (1979), pp. 93-97.
1392 ## P. Rozsa, On the inverse of band matrices, Integral Equations and 1392 ## P. Rozsa, On the inverse of band matrices, Integral Equations and
1393 ## Operator Theory, 10 (1987), pp. 82-95. 1393 ## Operator Theory, 10 (1987), pp. 82-95.
1394 1394
1395 if (nargin < 1 || nargin > 2) 1395 if (nargin < 1 || nargin > 2)
1396 error ("gallery: 1 to 2 arguments are required for invhess matrix."); 1396 error ("gallery: 1 to 2 arguments are required for invhess matrix.");
1397 elseif (! isnumeric (x)) 1397 elseif (! isnumeric (x))
1398 error ("gallery: X must be numeric for invhess matrix."); 1398 error ("gallery: X must be numeric for invhess matrix.");
1423 endfor 1423 endfor
1424 endfunction 1424 endfunction
1425 1425
1426 function A = invol (n) 1426 function A = invol (n)
1427 ## INVOL An involutory matrix. 1427 ## INVOL An involutory matrix.
1428 ## A = INVOL(N) is an N-by-N involutory (A*A = EYE(N)) and 1428 ## A = INVOL(N) is an N-by-N involutory (A*A = EYE(N)) and
1429 ## ill-conditioned matrix. 1429 ## ill-conditioned matrix.
1430 ## It is a diagonally scaled version of HILB(N). 1430 ## It is a diagonally scaled version of HILB(N).
1431 ## NB: B = (EYE(N)-A)/2 and B = (EYE(N)+A)/2 are idempotent (B*B = B). 1431 ## NB: B = (EYE(N)-A)/2 and B = (EYE(N)+A)/2 are idempotent (B*B = B).
1432 ## 1432 ##
1433 ## Reference: 1433 ## Reference:
1434 ## A.S. Householder and J.A. Carpenter, The singular values 1434 ## A.S. Householder and J.A. Carpenter, The singular values
1435 ## of involutory and of idempotent matrices, Numer. Math. 5 (1963), 1435 ## of involutory and of idempotent matrices, Numer. Math. 5 (1963),
1436 ## pp. 234-237. 1436 ## pp. 234-237.
1437 1437
1438 if (nargin != 1) 1438 if (nargin != 1)
1439 error ("gallery: 1 argument is required for invol matrix."); 1439 error ("gallery: 1 argument is required for invol matrix.");
1440 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1440 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1441 error ("gallery: N must be an integer for invol matrix."); 1441 error ("gallery: N must be an integer for invol matrix.");
1452 endfor 1452 endfor
1453 endfunction 1453 endfunction
1454 1454
1455 function [A, detA] = ipjfact (n, k = 0) 1455 function [A, detA] = ipjfact (n, k = 0)
1456 ## IPJFACT A Hankel matrix with factorial elements. 1456 ## IPJFACT A Hankel matrix with factorial elements.
1457 ## A = IPJFACT(N, K) is the matrix with 1457 ## A = IPJFACT(N, K) is the matrix with
1458 ## A(i,j) = (i+j)! (K = 0, default) 1458 ## A(i,j) = (i+j)! (K = 0, default)
1459 ## A(i,j) = 1/(i+j)! (K = 1) 1459 ## A(i,j) = 1/(i+j)! (K = 1)
1460 ## Both are Hankel matrices. 1460 ## Both are Hankel matrices.
1461 ## The determinant and inverse are known explicitly. 1461 ## The determinant and inverse are known explicitly.
1462 ## If a second output argument is present, d = DET(A) is returned: 1462 ## If a second output argument is present, d = DET(A) is returned:
1463 ## [A, d] = IPJFACT(N, K); 1463 ## [A, d] = IPJFACT(N, K);
1464 ## 1464 ##
1465 ## Suggested by P. R. Graves-Morris. 1465 ## Suggested by P. R. Graves-Morris.
1466 ## 1466 ##
1467 ## Reference: 1467 ## Reference:
1468 ## M.J.C. Gover, The explicit inverse of factorial Hankel matrices, 1468 ## M.J.C. Gover, The explicit inverse of factorial Hankel matrices,
1469 ## Dept. of Mathematics, University of Bradford, 1993. 1469 ## Dept. of Mathematics, University of Bradford, 1993.
1470 1470
1471 if (nargin < 1 || nargin > 2) 1471 if (nargin < 1 || nargin > 2)
1472 error ("gallery: 1 to 2 arguments are required for ipjfact matrix."); 1472 error ("gallery: 1 to 2 arguments are required for ipjfact matrix.");
1473 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1473 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1474 error ("gallery: N must be an integer for ipjfact matrix."); 1474 error ("gallery: N must be an integer for ipjfact matrix.");
1513 endif 1513 endif
1514 endfunction 1514 endfunction
1515 1515
1516 function J = jordbloc (n, lambda = 1) 1516 function J = jordbloc (n, lambda = 1)
1517 ## JORDBLOC Jordan block. 1517 ## JORDBLOC Jordan block.
1518 ## JORDBLOC(N, LAMBDA) is the N-by-N Jordan block with eigenvalue 1518 ## JORDBLOC(N, LAMBDA) is the N-by-N Jordan block with eigenvalue
1519 ## LAMBDA. LAMBDA = 1 is the default. 1519 ## LAMBDA. LAMBDA = 1 is the default.
1520 1520
1521 if (nargin < 1 || nargin > 2) 1521 if (nargin < 1 || nargin > 2)
1522 error ("gallery: 1 to 2 arguments are required for jordbloc matrix."); 1522 error ("gallery: 1 to 2 arguments are required for jordbloc matrix.");
1523 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1523 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1524 error ("gallery: N must be an integer for jordbloc matrix."); 1524 error ("gallery: N must be an integer for jordbloc matrix.");
1529 J = lambda * eye (n) + diag (ones (n-1, 1), 1); 1529 J = lambda * eye (n) + diag (ones (n-1, 1), 1);
1530 endfunction 1530 endfunction
1531 1531
1532 function U = kahan (n, theta = 1.2, pert = 25) 1532 function U = kahan (n, theta = 1.2, pert = 25)
1533 ## KAHAN Kahan matrix - upper trapezoidal. 1533 ## KAHAN Kahan matrix - upper trapezoidal.
1534 ## KAHAN(N, THETA) is an upper trapezoidal matrix 1534 ## KAHAN(N, THETA) is an upper trapezoidal matrix
1535 ## that has some interesting properties regarding estimation of 1535 ## that has some interesting properties regarding estimation of
1536 ## condition and rank. 1536 ## condition and rank.
1537 ## The matrix is N-by-N unless N is a 2-vector, in which case it 1537 ## The matrix is N-by-N unless N is a 2-vector, in which case it
1538 ## is N(1)-by-N(2). 1538 ## is N(1)-by-N(2).
1539 ## The parameter THETA defaults to 1.2. 1539 ## The parameter THETA defaults to 1.2.
1540 ## The useful range of THETA is 0 < THETA < PI. 1540 ## The useful range of THETA is 0 < THETA < PI.
1541 ## 1541 ##
1542 ## To ensure that the QR factorization with column pivoting does not 1542 ## To ensure that the QR factorization with column pivoting does not
1543 ## interchange columns in the presence of rounding errors, the diagonal 1543 ## interchange columns in the presence of rounding errors, the diagonal
1544 ## is perturbed by PERT*EPS*diag( [N:-1:1] ). 1544 ## is perturbed by PERT*EPS*diag( [N:-1:1] ).
1545 ## The default is PERT = 25, which ensures no interchanges for KAHAN(N) 1545 ## The default is PERT = 25, which ensures no interchanges for KAHAN(N)
1546 ## up to at least N = 90 in IEEE arithmetic. 1546 ## up to at least N = 90 in IEEE arithmetic.
1547 ## KAHAN(N, THETA, PERT) uses the given value of PERT. 1547 ## KAHAN(N, THETA, PERT) uses the given value of PERT.
1548 ## 1548 ##
1549 ## The inverse of KAHAN(N, THETA) is known explicitly: see 1549 ## The inverse of KAHAN(N, THETA) is known explicitly: see
1550 ## Higham (1987, p. 588), for example. 1550 ## Higham (1987, p. 588), for example.
1551 ## The diagonal perturbation was suggested by Christian Bischof. 1551 ## The diagonal perturbation was suggested by Christian Bischof.
1552 ## 1552 ##
1553 ## References: 1553 ## References:
1554 ## W. Kahan, Numerical linear algebra, Canadian Math. Bulletin, 1554 ## W. Kahan, Numerical linear algebra, Canadian Math. Bulletin,
1555 ## 9 (1966), pp. 757-801. 1555 ## 9 (1966), pp. 757-801.
1556 ## N.J. Higham, A survey of condition number estimation for 1556 ## N.J. Higham, A survey of condition number estimation for
1557 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596. 1557 ## triangular matrices, SIAM Review, 29 (1987), pp. 575-596.
1558 1558
1559 if (nargin < 1 || nargin > 3) 1559 if (nargin < 1 || nargin > 3)
1560 error ("gallery: 1 to 3 arguments are required for kahan matrix."); 1560 error ("gallery: 1 to 3 arguments are required for kahan matrix.");
1561 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) 1561 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n)
1562 error ("gallery: N must be a 1 or 2 element integer for kahan matrix."); 1562 error ("gallery: N must be a 1 or 2 element integer for kahan matrix.");
1582 endif 1582 endif
1583 endfunction 1583 endfunction
1584 1584
1585 function A = kms (n, rho = 0.5) 1585 function A = kms (n, rho = 0.5)
1586 ## KMS Kac-Murdock-Szego Toeplitz matrix. 1586 ## KMS Kac-Murdock-Szego Toeplitz matrix.
1587 ## A = KMS(N, RHO) is the N-by-N Kac-Murdock-Szego Toeplitz matrix with 1587 ## A = KMS(N, RHO) is the N-by-N Kac-Murdock-Szego Toeplitz matrix with
1588 ## A(i,j) = RHO^(ABS((i-j))) (for real RHO). 1588 ## A(i,j) = RHO^(ABS((i-j))) (for real RHO).
1589 ## If RHO is complex, then the same formula holds except that elements 1589 ## If RHO is complex, then the same formula holds except that elements
1590 ## below the diagonal are conjugated. 1590 ## below the diagonal are conjugated.
1591 ## RHO defaults to 0.5. 1591 ## RHO defaults to 0.5.
1592 ## Properties: 1592 ## Properties:
1593 ## A has an LDL' factorization with 1593 ## A has an LDL' factorization with
1594 ## L = INV(TRIW(N,-RHO,1)'), 1594 ## L = INV(TRIW(N,-RHO,1)'),
1595 ## D(i,i) = (1-ABS(RHO)^2)*EYE(N) except D(1,1) = 1. 1595 ## D(i,i) = (1-ABS(RHO)^2)*EYE(N) except D(1,1) = 1.
1596 ## A is positive definite if and only if 0 < ABS(RHO) < 1. 1596 ## A is positive definite if and only if 0 < ABS(RHO) < 1.
1597 ## INV(A) is tridiagonal. 1597 ## INV(A) is tridiagonal.
1598 ## 1598 ##
1599 ## Reference: 1599 ## Reference:
1600 ## W.F. Trench, Numerical solution of the eigenvalue problem 1600 ## W.F. Trench, Numerical solution of the eigenvalue problem
1601 ## for Hermitian Toeplitz matrices, SIAM J. Matrix Analysis and Appl., 1601 ## for Hermitian Toeplitz matrices, SIAM J. Matrix Analysis and Appl.,
1602 ## 10 (1989), pp. 135-146 (and see the references therein). 1602 ## 10 (1989), pp. 135-146 (and see the references therein).
1603 1603
1604 if (nargin < 1 || nargin > 2) 1604 if (nargin < 1 || nargin > 2)
1605 error ("gallery: 1 to 2 arguments are required for lauchli matrix."); 1605 error ("gallery: 1 to 2 arguments are required for lauchli matrix.");
1606 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1606 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1607 error ("gallery: N must be an integer for lauchli matrix.") 1607 error ("gallery: N must be an integer for lauchli matrix.")
1617 endif 1617 endif
1618 endfunction 1618 endfunction
1619 1619
1620 function B = krylov (A, x, j) 1620 function B = krylov (A, x, j)
1621 ## KRYLOV Krylov matrix. 1621 ## KRYLOV Krylov matrix.
1622 ## KRYLOV(A, x, j) is the Krylov matrix 1622 ## KRYLOV(A, x, j) is the Krylov matrix
1623 ## [x, Ax, A^2x, ..., A^(j-1)x], 1623 ## [x, Ax, A^2x, ..., A^(j-1)x],
1624 ## where A is an n-by-n matrix and x is an n-vector. 1624 ## where A is an n-by-n matrix and x is an n-vector.
1625 ## Defaults: x = ONES(n,1), j = n. 1625 ## Defaults: x = ONES(n,1), j = n.
1626 ## KRYLOV(n) is the same as KRYLOV(RANDN(n)). 1626 ## KRYLOV(n) is the same as KRYLOV(RANDN(n)).
1627 ## 1627 ##
1628 ## Reference: 1628 ## Reference:
1629 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, 1629 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
1630 ## Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369. 1630 ## Johns Hopkins University Press, Baltimore, Maryland, 1989, p. 369.
1631 1631
1632 if (nargin < 1 || nargin > 3) 1632 if (nargin < 1 || nargin > 3)
1633 error ("gallery: 1 to 3 arguments are required for krylov matrix."); 1633 error ("gallery: 1 to 3 arguments are required for krylov matrix.");
1634 elseif (! isnumeric (A) || ! issquare (A) || ndims (A) != 2) 1634 elseif (! isnumeric (A) || ! issquare (A) || ndims (A) != 2)
1635 error ("gallery: A must be a square 2-D matrix for krylov matrix."); 1635 error ("gallery: A must be a square 2-D matrix for krylov matrix.");
1660 endfor 1660 endfor
1661 endfunction 1661 endfunction
1662 1662
1663 function A = lauchli (n, mu = sqrt (eps)) 1663 function A = lauchli (n, mu = sqrt (eps))
1664 ## LAUCHLI Lauchli matrix - rectangular. 1664 ## LAUCHLI Lauchli matrix - rectangular.
1665 ## LAUCHLI(N, MU) is the (N+1)-by-N matrix [ONES(1,N); MU*EYE(N))]. 1665 ## LAUCHLI(N, MU) is the (N+1)-by-N matrix [ONES(1,N); MU*EYE(N))].
1666 ## It is a well-known example in least squares and other problems 1666 ## It is a well-known example in least squares and other problems
1667 ## that indicates the dangers of forming A'*A. 1667 ## that indicates the dangers of forming A'*A.
1668 ## MU defaults to SQRT(EPS). 1668 ## MU defaults to SQRT(EPS).
1669 ## 1669 ##
1670 ## Reference: 1670 ## Reference:
1671 ## P. Lauchli, Jordan-Elimination und Ausgleichung nach 1671 ## P. Lauchli, Jordan-Elimination und Ausgleichung nach
1672 ## kleinsten Quadraten, Numer. Math, 3 (1961), pp. 226-240. 1672 ## kleinsten Quadraten, Numer. Math, 3 (1961), pp. 226-240.
1673 1673
1674 if (nargin < 1 || nargin > 2) 1674 if (nargin < 1 || nargin > 2)
1675 error ("gallery: 1 to 2 arguments are required for lauchli matrix."); 1675 error ("gallery: 1 to 2 arguments are required for lauchli matrix.");
1676 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1676 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1677 error ("gallery: N must be an integer for lauchli matrix."); 1677 error ("gallery: N must be an integer for lauchli matrix.");
1683 mu*eye(n) ]; 1683 mu*eye(n) ];
1684 endfunction 1684 endfunction
1685 1685
1686 function A = lehmer (n) 1686 function A = lehmer (n)
1687 ## LEHMER Lehmer matrix - symmetric positive definite. 1687 ## LEHMER Lehmer matrix - symmetric positive definite.
1688 ## A = LEHMER(N) is the symmetric positive definite N-by-N matrix with 1688 ## A = LEHMER(N) is the symmetric positive definite N-by-N matrix with
1689 ## A(i,j) = i/j for j >= i. 1689 ## A(i,j) = i/j for j >= i.
1690 ## A is totally nonnegative. INV(A) is tridiagonal, and explicit 1690 ## A is totally nonnegative. INV(A) is tridiagonal, and explicit
1691 ## formulas are known for its entries. 1691 ## formulas are known for its entries.
1692 ## N <= COND(A) <= 4*N*N. 1692 ## N <= COND(A) <= 4*N*N.
1693 ## 1693 ##
1694 ## References: 1694 ## References:
1695 ## M. Newman and J. Todd, The evaluation of matrix inversion 1695 ## M. Newman and J. Todd, The evaluation of matrix inversion
1696 ## programs, J. Soc. Indust. Appl. Math., 6 (1958), pp. 466-476. 1696 ## programs, J. Soc. Indust. Appl. Math., 6 (1958), pp. 466-476.
1697 ## Solutions to problem E710 (proposed by D.H. Lehmer): The inverse 1697 ## Solutions to problem E710 (proposed by D.H. Lehmer): The inverse
1698 ## of a matrix, Amer. Math. Monthly, 53 (1946), pp. 534-535. 1698 ## of a matrix, Amer. Math. Monthly, 53 (1946), pp. 534-535.
1699 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, 1699 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra,
1700 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 154. 1700 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 154.
1701 1701
1702 if (nargin != 1) 1702 if (nargin != 1)
1703 error ("gallery: 1 argument is required for lehmer matrix."); 1703 error ("gallery: 1 argument is required for lehmer matrix.");
1704 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1704 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1705 error ("gallery: N must be an integer for lehmer matrix."); 1705 error ("gallery: N must be an integer for lehmer matrix.");
1710 A = tril (A) + tril (A, -1)'; 1710 A = tril (A) + tril (A, -1)';
1711 endfunction 1711 endfunction
1712 1712
1713 function T = lesp (n) 1713 function T = lesp (n)
1714 ## LESP A tridiagonal matrix with real, sensitive eigenvalues. 1714 ## LESP A tridiagonal matrix with real, sensitive eigenvalues.
1715 ## LESP(N) is an N-by-N matrix whose eigenvalues are real and smoothly 1715 ## LESP(N) is an N-by-N matrix whose eigenvalues are real and smoothly
1716 ## distributed in the interval approximately [-2*N-3.5, -4.5]. 1716 ## distributed in the interval approximately [-2*N-3.5, -4.5].
1717 ## The sensitivities of the eigenvalues increase exponentially as 1717 ## The sensitivities of the eigenvalues increase exponentially as
1718 ## the eigenvalues grow more negative. 1718 ## the eigenvalues grow more negative.
1719 ## The matrix is similar to the symmetric tridiagonal matrix with 1719 ## The matrix is similar to the symmetric tridiagonal matrix with
1720 ## the same diagonal entries and with off-diagonal entries 1, 1720 ## the same diagonal entries and with off-diagonal entries 1,
1721 ## via a similarity transformation with D = diag(1!,2!,...,N!). 1721 ## via a similarity transformation with D = diag(1!,2!,...,N!).
1722 ## 1722 ##
1723 ## References: 1723 ## References:
1724 ## H.W.J. Lenferink and M.N. Spijker, On the use of stability regions in 1724 ## H.W.J. Lenferink and M.N. Spijker, On the use of stability regions in
1725 ## the numerical analysis of initial value problems, 1725 ## the numerical analysis of initial value problems,
1726 ## Math. Comp., 57 (1991), pp. 221-237. 1726 ## Math. Comp., 57 (1991), pp. 221-237.
1727 ## L.N. Trefethen, Pseudospectra of matrices, in Numerical Analysis 1991, 1727 ## L.N. Trefethen, Pseudospectra of matrices, in Numerical Analysis 1991,
1728 ## Proceedings of the 14th Dundee Conference, 1728 ## Proceedings of the 14th Dundee Conference,
1729 ## D.F. Griffiths and G.A. Watson, eds, Pitman Research Notes in 1729 ## D.F. Griffiths and G.A. Watson, eds, Pitman Research Notes in
1730 ## Mathematics, volume 260, Longman Scientific and Technical, Essex, 1730 ## Mathematics, volume 260, Longman Scientific and Technical, Essex,
1731 ## UK, 1992, pp. 234-266. 1731 ## UK, 1992, pp. 234-266.
1732 1732
1733 if (nargin != 1) 1733 if (nargin != 1)
1734 error ("gallery: 1 argument is required for lesp matrix."); 1734 error ("gallery: 1 argument is required for lesp matrix.");
1735 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1735 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1736 error ("gallery: N must be an integer for lesp matrix."); 1736 error ("gallery: N must be an integer for lesp matrix.");
1740 T = full (tridiag (ones (size (x)) ./x, -(2*[x n+1]+1), x)); 1740 T = full (tridiag (ones (size (x)) ./x, -(2*[x n+1]+1), x));
1741 endfunction 1741 endfunction
1742 1742
1743 function A = lotkin (n) 1743 function A = lotkin (n)
1744 ## LOTKIN Lotkin matrix. 1744 ## LOTKIN Lotkin matrix.
1745 ## A = LOTKIN(N) is the Hilbert matrix with its first row altered to 1745 ## A = LOTKIN(N) is the Hilbert matrix with its first row altered to
1746 ## all ones. A is unsymmetric, ill-conditioned, and has many negative 1746 ## all ones. A is unsymmetric, ill-conditioned, and has many negative
1747 ## eigenvalues of small magnitude. 1747 ## eigenvalues of small magnitude.
1748 ## The inverse has integer entries and is known explicitly. 1748 ## The inverse has integer entries and is known explicitly.
1749 ## 1749 ##
1750 ## Reference: 1750 ## Reference:
1751 ## M. Lotkin, A set of test matrices, MTAC, 9 (1955), pp. 153-161. 1751 ## M. Lotkin, A set of test matrices, MTAC, 9 (1955), pp. 153-161.
1752 1752
1753 if (nargin != 1) 1753 if (nargin != 1)
1754 error ("gallery: 1 argument is required for lotkin matrix."); 1754 error ("gallery: 1 argument is required for lotkin matrix.");
1755 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1755 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1756 error ("gallery: N must be an integer for lotkin matrix."); 1756 error ("gallery: N must be an integer for lotkin matrix.");
1760 A(1,:) = ones (1, n); 1760 A(1,:) = ones (1, n);
1761 endfunction 1761 endfunction
1762 1762
1763 function A = minij (n) 1763 function A = minij (n)
1764 ## MINIJ Symmetric positive definite matrix MIN(i,j). 1764 ## MINIJ Symmetric positive definite matrix MIN(i,j).
1765 ## A = MINIJ(N) is the N-by-N symmetric positive definite matrix with 1765 ## A = MINIJ(N) is the N-by-N symmetric positive definite matrix with
1766 ## A(i,j) = MIN(i,j). 1766 ## A(i,j) = MIN(i,j).
1767 ## Properties, variations: 1767 ## Properties, variations:
1768 ## INV(A) is tridiagonal: it is minus the second difference matrix 1768 ## INV(A) is tridiagonal: it is minus the second difference matrix
1769 ## except its (N,N) element is 1. 1769 ## except its (N,N) element is 1.
1770 ## 2*A-ONES(N) (Givens' matrix) has tridiagonal inverse and 1770 ## 2*A-ONES(N) (Givens' matrix) has tridiagonal inverse and
1771 ## eigenvalues .5*sec^2([2r-1)PI/4N], r=1:N. 1771 ## eigenvalues .5*sec^2([2r-1)PI/4N], r=1:N.
1772 ## (N+1)*ONES(N)-A also has a tridiagonal inverse. 1772 ## (N+1)*ONES(N)-A also has a tridiagonal inverse.
1773 ## 1773 ##
1774 ## References: 1774 ## References:
1775 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, 1775 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra,
1776 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 158. 1776 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 158.
1777 ## D.E. Rutherford, Some continuant determinants arising in physics and 1777 ## D.E. Rutherford, Some continuant determinants arising in physics and
1778 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. 1778 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241.
1779 ## (For the eigenvalues of Givens' matrix.) 1779 ## (For the eigenvalues of Givens' matrix.)
1780 1780
1781 if (nargin != 1) 1781 if (nargin != 1)
1782 error ("gallery: 1 argument is required for minij matrix."); 1782 error ("gallery: 1 argument is required for minij matrix.");
1783 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1783 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1784 error ("gallery: N must be an integer for minij matrix."); 1784 error ("gallery: N must be an integer for minij matrix.");
1787 A = min (ones (n, 1) * (1:n), (1:n)' * ones (1, n)); 1787 A = min (ones (n, 1) * (1:n), (1:n)' * ones (1, n));
1788 endfunction 1788 endfunction
1789 1789
1790 function A = moler (n, alpha = -1) 1790 function A = moler (n, alpha = -1)
1791 ## MOLER Moler matrix - symmetric positive definite. 1791 ## MOLER Moler matrix - symmetric positive definite.
1792 ## A = MOLER(N, ALPHA) is the symmetric positive definite N-by-N matrix 1792 ## A = MOLER(N, ALPHA) is the symmetric positive definite N-by-N matrix
1793 ## U'*U where U = TRIW(N, ALPHA). 1793 ## U'*U where U = TRIW(N, ALPHA).
1794 ## For ALPHA = -1 (the default) A(i,j) = MIN(i,j)-2, A(i,i) = i. 1794 ## For ALPHA = -1 (the default) A(i,j) = MIN(i,j)-2, A(i,i) = i.
1795 ## A has one small eigenvalue. 1795 ## A has one small eigenvalue.
1796 ## 1796 ##
1797 ## Nash (1990) attributes the ALPHA = -1 matrix to Moler. 1797 ## Nash (1990) attributes the ALPHA = -1 matrix to Moler.
1798 ## 1798 ##
1799 ## Reference: 1799 ## Reference:
1800 ## J.C. Nash, Compact Numerical Methods for Computers: Linear 1800 ## J.C. Nash, Compact Numerical Methods for Computers: Linear
1801 ## Algebra and Function Minimisation, second edition, Adam Hilger, 1801 ## Algebra and Function Minimisation, second edition, Adam Hilger,
1802 ## Bristol, 1990 (Appendix 1). 1802 ## Bristol, 1990 (Appendix 1).
1803 1803
1804 if (nargin < 1 || nargin > 2) 1804 if (nargin < 1 || nargin > 2)
1805 error ("gallery: 1 to 2 arguments are required for moler matrix."); 1805 error ("gallery: 1 to 2 arguments are required for moler matrix.");
1806 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1806 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1807 error ("gallery: N must be an integer for moler matrix."); 1807 error ("gallery: N must be an integer for moler matrix.");
1812 A = triw (n, alpha)' * triw (n, alpha); 1812 A = triw (n, alpha)' * triw (n, alpha);
1813 endfunction 1813 endfunction
1814 1814
1815 function [A, T] = neumann (n) 1815 function [A, T] = neumann (n)
1816 ## NEUMANN Singular matrix from the discrete Neumann problem (sparse). 1816 ## NEUMANN Singular matrix from the discrete Neumann problem (sparse).
1817 ## NEUMANN(N) is the singular, row diagonally dominant matrix resulting 1817 ## NEUMANN(N) is the singular, row diagonally dominant matrix resulting
1818 ## from discretizing the Neumann problem with the usual five point 1818 ## from discretizing the Neumann problem with the usual five point
1819 ## operator on a regular mesh. 1819 ## operator on a regular mesh.
1820 ## It has a one-dimensional null space with null vector ONES(N,1). 1820 ## It has a one-dimensional null space with null vector ONES(N,1).
1821 ## The dimension N should be a perfect square, or else a 2-vector, 1821 ## The dimension N should be a perfect square, or else a 2-vector,
1822 ## in which case the dimension of the matrix is N(1)*N(2). 1822 ## in which case the dimension of the matrix is N(1)*N(2).
1823 ## 1823 ##
1824 ## Reference: 1824 ## Reference:
1825 ## R.J. Plemmons, Regular splittings and the discrete Neumann 1825 ## R.J. Plemmons, Regular splittings and the discrete Neumann
1826 ## problem, Numer. Math., 25 (1976), pp. 153-161. 1826 ## problem, Numer. Math., 25 (1976), pp. 153-161.
1827 1827
1828 if (nargin != 1) 1828 if (nargin != 1)
1829 error ("gallery: 1 argument is required for neumann matrix."); 1829 error ("gallery: 1 argument is required for neumann matrix.");
1830 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) 1830 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n)
1831 error ("gallery: N must be a 1 or 2 element integer for neumann matrix."); 1831 error ("gallery: N must be a 1 or 2 element integer for neumann matrix.");
1888 1888
1889 endfunction 1889 endfunction
1890 1890
1891 function Q = orthog (n, k = 1) 1891 function Q = orthog (n, k = 1)
1892 ## ORTHOG Orthogonal and nearly orthogonal matrices. 1892 ## ORTHOG Orthogonal and nearly orthogonal matrices.
1893 ## Q = ORTHOG(N, K) selects the K'th type of matrix of order N. 1893 ## Q = ORTHOG(N, K) selects the K'th type of matrix of order N.
1894 ## K > 0 for exactly orthogonal matrices, K < 0 for diagonal scalings of 1894 ## K > 0 for exactly orthogonal matrices, K < 0 for diagonal scalings of
1895 ## orthogonal matrices. 1895 ## orthogonal matrices.
1896 ## Available types: (K = 1 is the default) 1896 ## Available types: (K = 1 is the default)
1897 ## K = 1: Q(i,j) = SQRT(2/(n+1)) * SIN( i*j*PI/(n+1) ) 1897 ## K = 1: Q(i,j) = SQRT(2/(n+1)) * SIN( i*j*PI/(n+1) )
1898 ## Symmetric eigenvector matrix for second difference matrix. 1898 ## Symmetric eigenvector matrix for second difference matrix.
1899 ## K = 2: Q(i,j) = 2/SQRT(2*n+1)) * SIN( 2*i*j*PI/(2*n+1) ) 1899 ## K = 2: Q(i,j) = 2/SQRT(2*n+1)) * SIN( 2*i*j*PI/(2*n+1) )
1900 ## Symmetric. 1900 ## Symmetric.
1901 ## K = 3: Q(r,s) = EXP(2*PI*i*(r-1)*(s-1)/n) / SQRT(n) (i=SQRT(-1)) 1901 ## K = 3: Q(r,s) = EXP(2*PI*i*(r-1)*(s-1)/n) / SQRT(n) (i=SQRT(-1))
1902 ## Unitary, the Fourier matrix. Q^4 is the identity. 1902 ## Unitary, the Fourier matrix. Q^4 is the identity.
1903 ## This is essentially the same matrix as FFT(EYE(N))/SQRT(N)! 1903 ## This is essentially the same matrix as FFT(EYE(N))/SQRT(N)!
1904 ## K = 4: Helmert matrix: a permutation of a lower Hessenberg matrix, 1904 ## K = 4: Helmert matrix: a permutation of a lower Hessenberg matrix,
1905 ## whose first row is ONES(1:N)/SQRT(N). 1905 ## whose first row is ONES(1:N)/SQRT(N).
1906 ## K = 5: Q(i,j) = SIN( 2*PI*(i-1)*(j-1)/n ) + COS( 2*PI*(i-1)*(j-1)/n ). 1906 ## K = 5: Q(i,j) = SIN( 2*PI*(i-1)*(j-1)/n ) + COS( 2*PI*(i-1)*(j-1)/n ).
1907 ## Symmetric matrix arising in the Hartley transform. 1907 ## Symmetric matrix arising in the Hartley transform.
1908 ## K = -1: Q(i,j) = COS( (i-1)*(j-1)*PI/(n-1) ) 1908 ## K = -1: Q(i,j) = COS( (i-1)*(j-1)*PI/(n-1) )
1909 ## Chebyshev Vandermonde-like matrix, based on extrema of T(n-1). 1909 ## Chebyshev Vandermonde-like matrix, based on extrema of T(n-1).
1910 ## K = -2: Q(i,j) = COS( (i-1)*(j-1/2)*PI/n) ) 1910 ## K = -2: Q(i,j) = COS( (i-1)*(j-1/2)*PI/n) )
1911 ## Chebyshev Vandermonde-like matrix, based on zeros of T(n). 1911 ## Chebyshev Vandermonde-like matrix, based on zeros of T(n).
1912 ## 1912 ##
1913 ## References: 1913 ## References:
1914 ## N.J. Higham and D.J. Higham, Large growth factors in Gaussian 1914 ## N.J. Higham and D.J. Higham, Large growth factors in Gaussian
1915 ## elimination with pivoting, SIAM J. Matrix Analysis and Appl., 1915 ## elimination with pivoting, SIAM J. Matrix Analysis and Appl.,
1916 ## 10 (1989), pp. 155-164. 1916 ## 10 (1989), pp. 155-164.
1917 ## P. Morton, On the eigenvectors of Schur's matrix, J. Number Theory, 1917 ## P. Morton, On the eigenvectors of Schur's matrix, J. Number Theory,
1918 ## 12 (1980), pp. 122-127. (Re. ORTHOG(N, 3)) 1918 ## 12 (1980), pp. 122-127. (Re. ORTHOG(N, 3))
1919 ## H.O. Lancaster, The Helmert Matrices, Amer. Math. Monthly, 72 (1965), 1919 ## H.O. Lancaster, The Helmert Matrices, Amer. Math. Monthly, 72 (1965),
1920 ## pp. 4-12. 1920 ## pp. 4-12.
1921 ## D. Bini and P. Favati, On a matrix algebra related to the discrete 1921 ## D. Bini and P. Favati, On a matrix algebra related to the discrete
1922 ## Hartley transform, SIAM J. Matrix Anal. Appl., 14 (1993), 1922 ## Hartley transform, SIAM J. Matrix Anal. Appl., 14 (1993),
1923 ## pp. 500-507. 1923 ## pp. 500-507.
1924 1924
1925 if (nargin < 1 || nargin > 2) 1925 if (nargin < 1 || nargin > 2)
1926 error ("gallery: 1 to 2 arguments are required for orthog matrix."); 1926 error ("gallery: 1 to 2 arguments are required for orthog matrix.");
1927 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1927 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1928 error ("gallery: N must be an integer for orthog matrix."); 1928 error ("gallery: N must be an integer for orthog matrix.");
1974 endswitch 1974 endswitch
1975 endfunction 1975 endfunction
1976 1976
1977 function A = parter (n) 1977 function A = parter (n)
1978 ## PARTER Parter matrix - a Toeplitz matrix with singular values near PI. 1978 ## PARTER Parter matrix - a Toeplitz matrix with singular values near PI.
1979 ## PARTER(N) is the matrix with (i,j) element 1/(i-j+0.5). 1979 ## PARTER(N) is the matrix with (i,j) element 1/(i-j+0.5).
1980 ## It is a Cauchy matrix and a Toeplitz matrix. 1980 ## It is a Cauchy matrix and a Toeplitz matrix.
1981 ## 1981 ##
1982 ## At the Second SIAM Conference on Linear Algebra, Raleigh, N.C., 1982 ## At the Second SIAM Conference on Linear Algebra, Raleigh, N.C.,
1983 ## 1985, Cleve Moler noted that most of the singular values of 1983 ## 1985, Cleve Moler noted that most of the singular values of
1984 ## PARTER(N) are very close to PI. An explanation of the phenomenon 1984 ## PARTER(N) are very close to PI. An explanation of the phenomenon
1985 ## was given by Parter; see also the paper by Tyrtyshnikov. 1985 ## was given by Parter; see also the paper by Tyrtyshnikov.
1986 ## 1986 ##
1987 ## References: 1987 ## References:
1988 ## The MathWorks Newsletter, Volume 1, Issue 1, March 1986, page 2. 1988 ## The MathWorks Newsletter, Volume 1, Issue 1, March 1986, page 2.
1989 ## S.V. Parter, On the distribution of the singular values of Toeplitz 1989 ## S.V. Parter, On the distribution of the singular values of Toeplitz
1990 ## matrices, Linear Algebra and Appl., 80 (1986), pp. 115-130. 1990 ## matrices, Linear Algebra and Appl., 80 (1986), pp. 115-130.
1991 ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications, 1991 ## E.E. Tyrtyshnikov, Cauchy-Toeplitz matrices and some applications,
1992 ## Linear Algebra and Appl., 149 (1991), pp. 1-18. 1992 ## Linear Algebra and Appl., 149 (1991), pp. 1-18.
1993 1993
1994 if (nargin != 1) 1994 if (nargin != 1)
1995 error ("gallery: 1 argument is required for parter matrix."); 1995 error ("gallery: 1 argument is required for parter matrix.");
1996 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 1996 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
1997 error ("gallery: N must be an integer for parter matrix."); 1997 error ("gallery: N must be an integer for parter matrix.");
2000 A = cauchy ((1:n) + 0.5, -(1:n)); 2000 A = cauchy ((1:n) + 0.5, -(1:n));
2001 endfunction 2001 endfunction
2002 2002
2003 function P = pei (n, alpha = 1) 2003 function P = pei (n, alpha = 1)
2004 ## PEI Pei matrix. 2004 ## PEI Pei matrix.
2005 ## PEI(N, ALPHA), where ALPHA is a scalar, is the symmetric matrix 2005 ## PEI(N, ALPHA), where ALPHA is a scalar, is the symmetric matrix
2006 ## ALPHA*EYE(N) + ONES(N). 2006 ## ALPHA*EYE(N) + ONES(N).
2007 ## If ALPHA is omitted then ALPHA = 1 is used. 2007 ## If ALPHA is omitted then ALPHA = 1 is used.
2008 ## The matrix is singular for ALPHA = 0, -N. 2008 ## The matrix is singular for ALPHA = 0, -N.
2009 ## 2009 ##
2010 ## Reference: 2010 ## Reference:
2011 ## M.L. Pei, A test matrix for inversion procedures, 2011 ## M.L. Pei, A test matrix for inversion procedures,
2012 ## Comm. ACM, 5 (1962), p. 508. 2012 ## Comm. ACM, 5 (1962), p. 508.
2013 2013
2014 if (nargin < 1 || nargin > 2) 2014 if (nargin < 1 || nargin > 2)
2015 error ("gallery: 1 to 2 arguments are required for pei matrix."); 2015 error ("gallery: 1 to 2 arguments are required for pei matrix.");
2016 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2016 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2017 error ("gallery: N must be an integer for pei matrix."); 2017 error ("gallery: N must be an integer for pei matrix.");
2022 P = alpha * eye (n) + ones (n); 2022 P = alpha * eye (n) + ones (n);
2023 endfunction 2023 endfunction
2024 2024
2025 function A = poisson (n) 2025 function A = poisson (n)
2026 ## POISSON Block tridiagonal matrix from Poisson's equation (sparse). 2026 ## POISSON Block tridiagonal matrix from Poisson's equation (sparse).
2027 ## POISSON(N) is the block tridiagonal matrix of order N^2 2027 ## POISSON(N) is the block tridiagonal matrix of order N^2
2028 ## resulting from discretizing Poisson's equation with the 2028 ## resulting from discretizing Poisson's equation with the
2029 ## 5-point operator on an N-by-N mesh. 2029 ## 5-point operator on an N-by-N mesh.
2030 ## 2030 ##
2031 ## Reference: 2031 ## Reference:
2032 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, 2032 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
2033 ## Johns Hopkins University Press, Baltimore, Maryland, 1989 2033 ## Johns Hopkins University Press, Baltimore, Maryland, 1989
2034 ## (Section 4.5.4). 2034 ## (Section 4.5.4).
2035 2035
2036 if (nargin != 1) 2036 if (nargin != 1)
2037 error ("gallery: 1 argument is required for poisson matrix."); 2037 error ("gallery: 1 argument is required for poisson matrix.");
2038 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2038 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2039 error ("gallery: N must be an integer for poisson matrix."); 2039 error ("gallery: N must be an integer for poisson matrix.");
2044 A = kron (I, S) + kron (S, I); 2044 A = kron (I, S) + kron (S, I);
2045 endfunction 2045 endfunction
2046 2046
2047 function A = prolate (n, w = 0.25) 2047 function A = prolate (n, w = 0.25)
2048 ## PROLATE Prolate matrix - symmetric, ill-conditioned Toeplitz matrix. 2048 ## PROLATE Prolate matrix - symmetric, ill-conditioned Toeplitz matrix.
2049 ## A = PROLATE(N, W) is the N-by-N prolate matrix with parameter W. 2049 ## A = PROLATE(N, W) is the N-by-N prolate matrix with parameter W.
2050 ## It is a symmetric Toeplitz matrix. 2050 ## It is a symmetric Toeplitz matrix.
2051 ## If 0 < W < 0.5 then 2051 ## If 0 < W < 0.5 then
2052 ## - A is positive definite 2052 ## - A is positive definite
2053 ## - the eigenvalues of A are distinct, lie in (0, 1), and 2053 ## - the eigenvalues of A are distinct, lie in (0, 1), and
2054 ## tend to cluster around 0 and 1. 2054 ## tend to cluster around 0 and 1.
2055 ## W defaults to 0.25. 2055 ## W defaults to 0.25.
2056 ## 2056 ##
2057 ## Reference: 2057 ## Reference:
2058 ## J.M. Varah. The Prolate matrix. Linear Algebra and Appl., 2058 ## J.M. Varah. The Prolate matrix. Linear Algebra and Appl.,
2059 ## 187:269--278, 1993. 2059 ## 187:269--278, 1993.
2060 2060
2061 if (nargin < 1 || nargin > 2) 2061 if (nargin < 1 || nargin > 2)
2062 error ("gallery: 1 to 2 arguments are required for prolate matrix."); 2062 error ("gallery: 1 to 2 arguments are required for prolate matrix.");
2063 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2063 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2064 error ("gallery: N must be an integer for prolate matrix."); 2064 error ("gallery: N must be an integer for prolate matrix.");
2074 endfunction 2074 endfunction
2075 2075
2076 function H = randhess (x) 2076 function H = randhess (x)
2077 ## NOTE: this function was named ohess in the original Test Matrix Toolbox 2077 ## NOTE: this function was named ohess in the original Test Matrix Toolbox
2078 ## RANDHESS Random, orthogonal upper Hessenberg matrix. 2078 ## RANDHESS Random, orthogonal upper Hessenberg matrix.
2079 ## H = RANDHESS(N) is an N-by-N real, random, orthogonal 2079 ## H = RANDHESS(N) is an N-by-N real, random, orthogonal
2080 ## upper Hessenberg matrix. 2080 ## upper Hessenberg matrix.
2081 ## Alternatively, H = RANDHESS(X), where X is an arbitrary real 2081 ## Alternatively, H = RANDHESS(X), where X is an arbitrary real
2082 ## N-vector (N > 1) constructs H non-randomly using the elements 2082 ## N-vector (N > 1) constructs H non-randomly using the elements
2083 ## of X as parameters. 2083 ## of X as parameters.
2084 ## In both cases H is constructed via a product of N-1 Givens rotations. 2084 ## In both cases H is constructed via a product of N-1 Givens rotations.
2085 ## 2085 ##
2086 ## Note: See Gragg (1986) for how to represent an N-by-N (complex) 2086 ## Note: See Gragg (1986) for how to represent an N-by-N (complex)
2087 ## unitary Hessenberg matrix with positive subdiagonal elements in terms 2087 ## unitary Hessenberg matrix with positive subdiagonal elements in terms
2088 ## of 2N-1 real parameters (the Schur parametrization). 2088 ## of 2N-1 real parameters (the Schur parametrization).
2089 ## This M-file handles the real case only and is intended simply as a 2089 ## This M-file handles the real case only and is intended simply as a
2090 ## convenient way to generate random or non-random orthogonal Hessenberg 2090 ## convenient way to generate random or non-random orthogonal Hessenberg
2091 ## matrices. 2091 ## matrices.
2092 ## 2092 ##
2093 ## Reference: 2093 ## Reference:
2094 ## W.B. Gragg, The QR algorithm for unitary Hessenberg matrices, 2094 ## W.B. Gragg, The QR algorithm for unitary Hessenberg matrices,
2095 ## J. Comp. Appl. Math., 16 (1986), pp. 1-8. 2095 ## J. Comp. Appl. Math., 16 (1986), pp. 1-8.
2096 2096
2097 if (nargin != 1) 2097 if (nargin != 1)
2098 error ("gallery: 1 argument is required for randhess matrix."); 2098 error ("gallery: 1 argument is required for randhess matrix.");
2099 elseif (! isnumeric (x) || ! isreal (x)) 2099 elseif (! isnumeric (x) || ! isreal (x))
2100 error ("gallery: N or X must be numeric real values for randhess matrix."); 2100 error ("gallery: N or X must be numeric real values for randhess matrix.");
2123 endfor 2123 endfor
2124 endfunction 2124 endfunction
2125 2125
2126 function A = rando (n, k = 1) 2126 function A = rando (n, k = 1)
2127 ## RANDO Random matrix with elements -1, 0 or 1. 2127 ## RANDO Random matrix with elements -1, 0 or 1.
2128 ## A = RANDO(N, K) is a random N-by-N matrix with elements from 2128 ## A = RANDO(N, K) is a random N-by-N matrix with elements from
2129 ## one of the following discrete distributions (default K = 1): 2129 ## one of the following discrete distributions (default K = 1):
2130 ## K = 1: A(i,j) = 0 or 1 with equal probability, 2130 ## K = 1: A(i,j) = 0 or 1 with equal probability,
2131 ## K = 2: A(i,j) = -1 or 1 with equal probability, 2131 ## K = 2: A(i,j) = -1 or 1 with equal probability,
2132 ## K = 3: A(i,j) = -1, 0 or 1 with equal probability. 2132 ## K = 3: A(i,j) = -1, 0 or 1 with equal probability.
2133 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2). 2133 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2).
2134 2134
2135 if (nargin < 1 || nargin > 2) 2135 if (nargin < 1 || nargin > 2)
2136 error ("gallery: 1 to 2 arguments are required for rando matrix."); 2136 error ("gallery: 1 to 2 arguments are required for rando matrix.");
2137 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) 2137 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n)
2138 error ("gallery: N must be an integer for rando matrix."); 2138 error ("gallery: N must be an integer for rando matrix.");
2154 2154
2155 endfunction 2155 endfunction
2156 2156
2157 function A = randsvd (n, kappa = sqrt (1/eps), mode = 3, kl = n-1, ku = kl) 2157 function A = randsvd (n, kappa = sqrt (1/eps), mode = 3, kl = n-1, ku = kl)
2158 ## RANDSVD Random matrix with pre-assigned singular values. 2158 ## RANDSVD Random matrix with pre-assigned singular values.
2159 ## RANDSVD(N, KAPPA, MODE, KL, KU) is a (banded) random matrix of order N 2159 ## RANDSVD(N, KAPPA, MODE, KL, KU) is a (banded) random matrix of order N
2160 ## with COND(A) = KAPPA and singular values from the distribution MODE. 2160 ## with COND(A) = KAPPA and singular values from the distribution MODE.
2161 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2). 2161 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2).
2162 ## Available types: 2162 ## Available types:
2163 ## MODE = 1: one large singular value, 2163 ## MODE = 1: one large singular value,
2164 ## MODE = 2: one small singular value, 2164 ## MODE = 2: one small singular value,
2165 ## MODE = 3: geometrically distributed singular values, 2165 ## MODE = 3: geometrically distributed singular values,
2166 ## MODE = 4: arithmetically distributed singular values, 2166 ## MODE = 4: arithmetically distributed singular values,
2167 ## MODE = 5: random singular values with unif. dist. logarithm. 2167 ## MODE = 5: random singular values with unif. dist. logarithm.
2168 ## If omitted, MODE defaults to 3, and KAPPA defaults to SQRT(1/EPS). 2168 ## If omitted, MODE defaults to 3, and KAPPA defaults to SQRT(1/EPS).
2169 ## If MODE < 0 then the effect is as for ABS(MODE) except that in the 2169 ## If MODE < 0 then the effect is as for ABS(MODE) except that in the
2170 ## original matrix of singular values the order of the diagonal entries 2170 ## original matrix of singular values the order of the diagonal entries
2171 ## is reversed: small to large instead of large to small. 2171 ## is reversed: small to large instead of large to small.
2172 ## KL and KU are the lower and upper bandwidths respectively; if they 2172 ## KL and KU are the lower and upper bandwidths respectively; if they
2173 ## are omitted a full matrix is produced. 2173 ## are omitted a full matrix is produced.
2174 ## If only KL is present, KU defaults to KL. 2174 ## If only KL is present, KU defaults to KL.
2175 ## Special case: if KAPPA < 0 then a random full symmetric positive 2175 ## Special case: if KAPPA < 0 then a random full symmetric positive
2176 ## definite matrix is produced with COND(A) = -KAPPA and 2176 ## definite matrix is produced with COND(A) = -KAPPA and
2177 ## eigenvalues distributed according to MODE. 2177 ## eigenvalues distributed according to MODE.
2178 ## KL and KU, if present, are ignored. 2178 ## KL and KU, if present, are ignored.
2179 ## 2179 ##
2180 ## Reference: 2180 ## Reference:
2181 ## N.J. Higham, Accuracy and Stability of Numerical Algorithms, 2181 ## N.J. Higham, Accuracy and Stability of Numerical Algorithms,
2182 ## Society for Industrial and Applied Mathematics, Philadelphia, PA, 2182 ## Society for Industrial and Applied Mathematics, Philadelphia, PA,
2183 ## USA, 1996; sec. 26.3. 2183 ## USA, 1996; sec. 26.3.
2184 ## 2184 ##
2185 ## This routine is similar to the more comprehensive Fortran routine xLATMS 2185 ## This routine is similar to the more comprehensive Fortran routine xLATMS
2186 ## in the following reference: 2186 ## in the following reference:
2187 ## J.W. Demmel and A. McKenney, A test matrix generation suite, 2187 ## J.W. Demmel and A. McKenney, A test matrix generation suite,
2188 ## LAPACK Working Note #9, Courant Institute of Mathematical Sciences, 2188 ## LAPACK Working Note #9, Courant Institute of Mathematical Sciences,
2189 ## New York, 1989. 2189 ## New York, 1989.
2190 2190
2191 if (nargin < 1 || nargin > 5) 2191 if (nargin < 1 || nargin > 5)
2192 error ("gallery: 1 to 5 arguments are required for randsvd matrix."); 2192 error ("gallery: 1 to 5 arguments are required for randsvd matrix.");
2193 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n) 2193 elseif (! isnumeric (n) || all (numel (n) != [1 2]) || fix (n) != n)
2194 error ("gallery: N must be a 1 or 2 element integer vector for randsvd matrix."); 2194 error ("gallery: N must be a 1 or 2 element integer vector for randsvd matrix.");
2243 error ("gallery: unknown MODE '%d' for randsvd matrix.", mode); 2243 error ("gallery: unknown MODE '%d' for randsvd matrix.", mode);
2244 endswitch 2244 endswitch
2245 2245
2246 ## Convert to diagonal matrix of singular values. 2246 ## Convert to diagonal matrix of singular values.
2247 if (mode < 0) 2247 if (mode < 0)
2248 sigma = sigma (p:-1:1); 2248 sigma = sigma(p:-1:1);
2249 endif 2249 endif
2250 sigma = diag (sigma); 2250 sigma = diag (sigma);
2251 2251
2252 if (posdef) 2252 if (posdef)
2253 ## handle case where KAPPA was negative 2253 ## handle case where KAPPA was negative
2278 endif 2278 endif
2279 endfunction 2279 endfunction
2280 2280
2281 function A = redheff (n) 2281 function A = redheff (n)
2282 ## REDHEFF A (0,1) matrix of Redheffer associated with the Riemann hypothesis. 2282 ## REDHEFF A (0,1) matrix of Redheffer associated with the Riemann hypothesis.
2283 ## A = REDHEFF(N) is an N-by-N matrix of 0s and 1s defined by 2283 ## A = REDHEFF(N) is an N-by-N matrix of 0s and 1s defined by
2284 ## A(i,j) = 1 if j = 1 or if i divides j, 2284 ## A(i,j) = 1 if j = 1 or if i divides j,
2285 ## A(i,j) = 0 otherwise. 2285 ## A(i,j) = 0 otherwise.
2286 ## It has N - FLOOR(LOG2(N)) - 1 eigenvalues equal to 1, 2286 ## It has N - FLOOR(LOG2(N)) - 1 eigenvalues equal to 1,
2287 ## a real eigenvalue (the spectral radius) approximately SQRT(N), 2287 ## a real eigenvalue (the spectral radius) approximately SQRT(N),
2288 ## a negative eigenvalue approximately -SQRT(N), 2288 ## a negative eigenvalue approximately -SQRT(N),
2289 ## and the remaining eigenvalues are provably ``small''. 2289 ## and the remaining eigenvalues are provably ``small''.
2290 ## Barrett and Jarvis (1992) conjecture that 2290 ## Barrett and Jarvis (1992) conjecture that
2291 ## ``the small eigenvalues all lie inside the unit circle 2291 ## ``the small eigenvalues all lie inside the unit circle
2292 ## ABS(Z) = 1'', 2292 ## ABS(Z) = 1'',
2293 ## and a proof of this conjecture, together with a proof that some 2293 ## and a proof of this conjecture, together with a proof that some
2294 ## eigenvalue tends to zero as N tends to infinity, would yield 2294 ## eigenvalue tends to zero as N tends to infinity, would yield
2295 ## a new proof of the prime number theorem. 2295 ## a new proof of the prime number theorem.
2296 ## The Riemann hypothesis is true if and only if 2296 ## The Riemann hypothesis is true if and only if
2297 ## DET(A) = O( N^(1/2+epsilon) ) for every epsilon > 0 2297 ## DET(A) = O( N^(1/2+epsilon) ) for every epsilon > 0
2298 ## (`!' denotes factorial). 2298 ## (`!' denotes factorial).
2299 ## See also RIEMANN. 2299 ## See also RIEMANN.
2300 ## 2300 ##
2301 ## Reference: 2301 ## Reference:
2302 ## W.W. Barrett and T.J. Jarvis, 2302 ## W.W. Barrett and T.J. Jarvis,
2303 ## Spectral Properties of a Matrix of Redheffer, 2303 ## Spectral Properties of a Matrix of Redheffer,
2304 ## Linear Algebra and Appl., 162 (1992), pp. 673-683. 2304 ## Linear Algebra and Appl., 162 (1992), pp. 673-683.
2305 2305
2306 if (nargin != 1) 2306 if (nargin != 1)
2307 error ("gallery: 1 argument is required for redheff matrix."); 2307 error ("gallery: 1 argument is required for redheff matrix.");
2308 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2308 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2309 error ("gallery: N must be an integer for redheff matrix."); 2309 error ("gallery: N must be an integer for redheff matrix.");
2314 A(:,1) = ones (n, 1); 2314 A(:,1) = ones (n, 1);
2315 endfunction 2315 endfunction
2316 2316
2317 function A = riemann (n) 2317 function A = riemann (n)
2318 ## RIEMANN A matrix associated with the Riemann hypothesis. 2318 ## RIEMANN A matrix associated with the Riemann hypothesis.
2319 ## A = RIEMANN(N) is an N-by-N matrix for which the 2319 ## A = RIEMANN(N) is an N-by-N matrix for which the
2320 ## Riemann hypothesis is true if and only if 2320 ## Riemann hypothesis is true if and only if
2321 ## DET(A) = O( N! N^(-1/2+epsilon) ) for every epsilon > 0 2321 ## DET(A) = O( N! N^(-1/2+epsilon) ) for every epsilon > 0
2322 ## (`!' denotes factorial). 2322 ## (`!' denotes factorial).
2323 ## A = B(2:N+1, 2:N+1), where 2323 ## A = B(2:N+1, 2:N+1), where
2324 ## B(i,j) = i-1 if i divides j and -1 otherwise. 2324 ## B(i,j) = i-1 if i divides j and -1 otherwise.
2325 ## Properties include, with M = N+1: 2325 ## Properties include, with M = N+1:
2326 ## Each eigenvalue E(i) satisfies ABS(E(i)) <= M - 1/M. 2326 ## Each eigenvalue E(i) satisfies ABS(E(i)) <= M - 1/M.
2327 ## i <= E(i) <= i+1 with at most M-SQRT(M) exceptions. 2327 ## i <= E(i) <= i+1 with at most M-SQRT(M) exceptions.
2328 ## All integers in the interval (M/3, M/2] are eigenvalues. 2328 ## All integers in the interval (M/3, M/2] are eigenvalues.
2329 ## 2329 ##
2330 ## See also REDHEFF. 2330 ## See also REDHEFF.
2331 ## 2331 ##
2332 ## Reference: 2332 ## Reference:
2333 ## F. Roesler, Riemann's hypothesis as an eigenvalue problem, 2333 ## F. Roesler, Riemann's hypothesis as an eigenvalue problem,
2334 ## Linear Algebra and Appl., 81 (1986), pp. 153-198. 2334 ## Linear Algebra and Appl., 81 (1986), pp. 153-198.
2335 2335
2336 if (nargin != 1) 2336 if (nargin != 1)
2337 error ("gallery: 1 argument is required for riemann matrix."); 2337 error ("gallery: 1 argument is required for riemann matrix.");
2338 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2338 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2339 error ("gallery: N must be an integer for riemann matrix."); 2339 error ("gallery: N must be an integer for riemann matrix.");
2346 endfunction 2346 endfunction
2347 2347
2348 function A = ris (n) 2348 function A = ris (n)
2349 ## NOTE: this function was named dingdong in the original Test Matrix Toolbox 2349 ## NOTE: this function was named dingdong in the original Test Matrix Toolbox
2350 ## RIS Dingdong matrix - a symmetric Hankel matrix. 2350 ## RIS Dingdong matrix - a symmetric Hankel matrix.
2351 ## A = RIS(N) is the symmetric N-by-N Hankel matrix with 2351 ## A = RIS(N) is the symmetric N-by-N Hankel matrix with
2352 ## A(i,j) = 0.5/(N-i-j+1.5). 2352 ## A(i,j) = 0.5/(N-i-j+1.5).
2353 ## The eigenvalues of A cluster around PI/2 and -PI/2. 2353 ## The eigenvalues of A cluster around PI/2 and -PI/2.
2354 ## 2354 ##
2355 ## Invented by F.N. Ris. 2355 ## Invented by F.N. Ris.
2356 ## 2356 ##
2357 ## Reference: 2357 ## Reference:
2358 ## J.C. Nash, Compact Numerical Methods for Computers: Linear 2358 ## J.C. Nash, Compact Numerical Methods for Computers: Linear
2359 ## Algebra and Function Minimisation, second edition, Adam Hilger, 2359 ## Algebra and Function Minimisation, second edition, Adam Hilger,
2360 ## Bristol, 1990 (Appendix 1). 2360 ## Bristol, 1990 (Appendix 1).
2361 2361
2362 if (nargin != 1) 2362 if (nargin != 1)
2363 error ("gallery: 1 argument is required for ris matrix."); 2363 error ("gallery: 1 argument is required for ris matrix.");
2364 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2364 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2365 error ("gallery: N must be an integer for ris matrix."); 2365 error ("gallery: N must be an integer for ris matrix.");
2369 A = cauchy (p); 2369 A = cauchy (p);
2370 endfunction 2370 endfunction
2371 2371
2372 function A = smoke (n, k = 0) 2372 function A = smoke (n, k = 0)
2373 ## SMOKE Smoke matrix - complex, with a `smoke ring' pseudospectrum. 2373 ## SMOKE Smoke matrix - complex, with a `smoke ring' pseudospectrum.
2374 ## SMOKE(N) is an N-by-N matrix with 1s on the 2374 ## SMOKE(N) is an N-by-N matrix with 1s on the
2375 ## superdiagonal, 1 in the (N,1) position, and powers of 2375 ## superdiagonal, 1 in the (N,1) position, and powers of
2376 ## roots of unity along the diagonal. 2376 ## roots of unity along the diagonal.
2377 ## SMOKE(N, 1) is the same except for a zero (N,1) element. 2377 ## SMOKE(N, 1) is the same except for a zero (N,1) element.
2378 ## The eigenvalues of SMOKE(N, 1) are the N'th roots of unity; 2378 ## The eigenvalues of SMOKE(N, 1) are the N'th roots of unity;
2379 ## those of SMOKE(N) are the N'th roots of unity times 2^(1/N). 2379 ## those of SMOKE(N) are the N'th roots of unity times 2^(1/N).
2380 ## 2380 ##
2381 ## Try PS(SMOKE(32)). For SMOKE(N, 1) the pseudospectrum looks 2381 ## Try PS(SMOKE(32)). For SMOKE(N, 1) the pseudospectrum looks
2382 ## like a sausage folded back on itself. 2382 ## like a sausage folded back on itself.
2383 ## GERSH(SMOKE(N, 1)) is interesting. 2383 ## GERSH(SMOKE(N, 1)) is interesting.
2384 ## 2384 ##
2385 ## Reference: 2385 ## Reference:
2386 ## L. Reichel and L.N. Trefethen, Eigenvalues and pseudo-eigenvalues of 2386 ## L. Reichel and L.N. Trefethen, Eigenvalues and pseudo-eigenvalues of
2387 ## Toeplitz matrices, Linear Algebra and Appl., 162-164:153-185, 1992. 2387 ## Toeplitz matrices, Linear Algebra and Appl., 162-164:153-185, 1992.
2388 2388
2389 if (nargin < 1 || nargin > 2) 2389 if (nargin < 1 || nargin > 2)
2390 error ("gallery: 1 to 2 arguments are required for smoke matrix."); 2390 error ("gallery: 1 to 2 arguments are required for smoke matrix.");
2391 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2391 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2392 error ("gallery: N must be an integer for smoke matrix."); 2392 error ("gallery: N must be an integer for smoke matrix.");
2406 endfunction 2406 endfunction
2407 2407
2408 function T = toeppd (n, m = n, w = rand (m,1), theta = rand (m,1)) 2408 function T = toeppd (n, m = n, w = rand (m,1), theta = rand (m,1))
2409 ## NOTE: this function was named pdtoep in the original Test Matrix Toolbox 2409 ## NOTE: this function was named pdtoep in the original Test Matrix Toolbox
2410 ## TOEPPD Symmetric positive definite Toeplitz matrix. 2410 ## TOEPPD Symmetric positive definite Toeplitz matrix.
2411 ## TOEPPD(N, M, W, THETA) is an N-by-N symmetric positive (semi-) 2411 ## TOEPPD(N, M, W, THETA) is an N-by-N symmetric positive (semi-)
2412 ## definite (SPD) Toeplitz matrix, comprised of the sum of M rank 2 2412 ## definite (SPD) Toeplitz matrix, comprised of the sum of M rank 2
2413 ## (or, for certain THETA, rank 1) SPD Toeplitz matrices. 2413 ## (or, for certain THETA, rank 1) SPD Toeplitz matrices.
2414 ## Specifically, 2414 ## Specifically,
2415 ## T = W(1)*T(THETA(1)) + ... + W(M)*T(THETA(M)), 2415 ## T = W(1)*T(THETA(1)) + ... + W(M)*T(THETA(M)),
2416 ## where T(THETA(k)) has (i,j) element COS(2*PI*THETA(k)*(i-j)). 2416 ## where T(THETA(k)) has (i,j) element COS(2*PI*THETA(k)*(i-j)).
2417 ## Defaults: M = N, W = RAND(M,1), THETA = RAND(M,1). 2417 ## Defaults: M = N, W = RAND(M,1), THETA = RAND(M,1).
2418 ## 2418 ##
2419 ## Reference: 2419 ## Reference:
2420 ## G. Cybenko and C.F. Van Loan, Computing the minimum eigenvalue of 2420 ## G. Cybenko and C.F. Van Loan, Computing the minimum eigenvalue of
2421 ## a symmetric positive definite Toeplitz matrix, SIAM J. Sci. Stat. 2421 ## a symmetric positive definite Toeplitz matrix, SIAM J. Sci. Stat.
2422 ## Comput., 7 (1986), pp. 123-131. 2422 ## Comput., 7 (1986), pp. 123-131.
2423 2423
2424 if (nargin < 1 || nargin > 4) 2424 if (nargin < 1 || nargin > 4)
2425 error ("gallery: 1 to 4 arguments are required for toeppd matrix."); 2425 error ("gallery: 1 to 4 arguments are required for toeppd matrix.");
2426 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2426 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2427 error ("gallery: N must be a numeric integer for toeppd matrix."); 2427 error ("gallery: N must be a numeric integer for toeppd matrix.");
2440 endfunction 2440 endfunction
2441 2441
2442 function P = toeppen (n, a = 1, b = -10, c = 0, d = 10, e = 1) 2442 function P = toeppen (n, a = 1, b = -10, c = 0, d = 10, e = 1)
2443 ## NOTE: this function was named pentoep in the original Test Matrix Toolbox 2443 ## NOTE: this function was named pentoep in the original Test Matrix Toolbox
2444 ## TOEPPEN Pentadiagonal Toeplitz matrix (sparse). 2444 ## TOEPPEN Pentadiagonal Toeplitz matrix (sparse).
2445 ## P = TOEPPEN(N, A, B, C, D, E) is the N-by-N pentadiagonal 2445 ## P = TOEPPEN(N, A, B, C, D, E) is the N-by-N pentadiagonal
2446 ## Toeplitz matrix with diagonals composed of the numbers 2446 ## Toeplitz matrix with diagonals composed of the numbers
2447 ## A =: P(3,1), B =: P(2,1), C =: P(1,1), D =: P(1,2), E =: P(1,3). 2447 ## A =: P(3,1), B =: P(2,1), C =: P(1,1), D =: P(1,2), E =: P(1,3).
2448 ## Default: (A,B,C,D,E) = (1,-10,0,10,1) (a matrix of Rutishauser). 2448 ## Default: (A,B,C,D,E) = (1,-10,0,10,1) (a matrix of Rutishauser).
2449 ## This matrix has eigenvalues lying approximately on 2449 ## This matrix has eigenvalues lying approximately on
2450 ## the line segment 2*cos(2*t) + 20*i*sin(t). 2450 ## the line segment 2*cos(2*t) + 20*i*sin(t).
2451 ## 2451 ##
2452 ## Interesting plots are 2452 ## Interesting plots are
2453 ## PS(FULL(TOEPPEN(32,0,1,0,0,1/4))) - `triangle' 2453 ## PS(FULL(TOEPPEN(32,0,1,0,0,1/4))) - `triangle'
2454 ## PS(FULL(TOEPPEN(32,0,1/2,0,0,1))) - `propeller' 2454 ## PS(FULL(TOEPPEN(32,0,1/2,0,0,1))) - `propeller'
2455 ## PS(FULL(TOEPPEN(32,0,1/2,1,1,1))) - `fish' 2455 ## PS(FULL(TOEPPEN(32,0,1/2,1,1,1))) - `fish'
2456 ## 2456 ##
2457 ## References: 2457 ## References:
2458 ## R.M. Beam and R.F. Warming, The asymptotic spectra of 2458 ## R.M. Beam and R.F. Warming, The asymptotic spectra of
2459 ## banded Toeplitz and quasi-Toeplitz matrices, SIAM J. Sci. 2459 ## banded Toeplitz and quasi-Toeplitz matrices, SIAM J. Sci.
2460 ## Comput. 14 (4), 1993, pp. 971-1006. 2460 ## Comput. 14 (4), 1993, pp. 971-1006.
2461 ## H. Rutishauser, On test matrices, Programmation en Mathematiques 2461 ## H. Rutishauser, On test matrices, Programmation en Mathematiques
2462 ## Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165, 2462 ## Numeriques, Editions Centre Nat. Recherche Sci., Paris, 165,
2463 ## 1966, pp. 349-365. 2463 ## 1966, pp. 349-365.
2464 2464
2465 if (nargin < 1 || nargin > 6) 2465 if (nargin < 1 || nargin > 6)
2466 error ("gallery: 1 to 6 arguments are required for toeppen matrix."); 2466 error ("gallery: 1 to 6 arguments are required for toeppen matrix.");
2467 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n) 2467 elseif (! isnumeric (n) || ! isscalar (n) || fix (n) != n)
2468 error ("gallery: N must be a numeric integer for toeppen matrix."); 2468 error ("gallery: N must be a numeric integer for toeppen matrix.");
2474 -2:2, n, n); 2474 -2:2, n, n);
2475 endfunction 2475 endfunction
2476 2476
2477 function T = tridiag (n, x = -1, y = 2, z = -1) 2477 function T = tridiag (n, x = -1, y = 2, z = -1)
2478 ## TRIDIAG Tridiagonal matrix (sparse). 2478 ## TRIDIAG Tridiagonal matrix (sparse).
2479 ## TRIDIAG(X, Y, Z) is the tridiagonal matrix with subdiagonal X, 2479 ## TRIDIAG(X, Y, Z) is the tridiagonal matrix with subdiagonal X,
2480 ## diagonal Y, and superdiagonal Z. 2480 ## diagonal Y, and superdiagonal Z.
2481 ## X and Z must be vectors of dimension one less than Y. 2481 ## X and Z must be vectors of dimension one less than Y.
2482 ## Alternatively TRIDIAG(N, C, D, E), where C, D, and E are all 2482 ## Alternatively TRIDIAG(N, C, D, E), where C, D, and E are all
2483 ## scalars, yields the Toeplitz tridiagonal matrix of order N 2483 ## scalars, yields the Toeplitz tridiagonal matrix of order N
2484 ## with subdiagonal elements C, diagonal elements D, and superdiagonal 2484 ## with subdiagonal elements C, diagonal elements D, and superdiagonal
2485 ## elements E. This matrix has eigenvalues (Todd 1977) 2485 ## elements E. This matrix has eigenvalues (Todd 1977)
2486 ## D + 2*SQRT(C*E)*COS(k*PI/(N+1)), k=1:N. 2486 ## D + 2*SQRT(C*E)*COS(k*PI/(N+1)), k=1:N.
2487 ## TRIDIAG(N) is the same as TRIDIAG(N,-1,2,-1), which is 2487 ## TRIDIAG(N) is the same as TRIDIAG(N,-1,2,-1), which is
2488 ## a symmetric positive definite M-matrix (the negative of the 2488 ## a symmetric positive definite M-matrix (the negative of the
2489 ## second difference matrix). 2489 ## second difference matrix).
2490 ## 2490 ##
2491 ## References: 2491 ## References:
2492 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra, 2492 ## J. Todd, Basic Numerical Mathematics, Vol. 2: Numerical Algebra,
2493 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 155. 2493 ## Birkhauser, Basel, and Academic Press, New York, 1977, p. 155.
2494 ## D.E. Rutherford, Some continuant determinants arising in physics and 2494 ## D.E. Rutherford, Some continuant determinants arising in physics and
2495 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241. 2495 ## chemistry---II, Proc. Royal Soc. Edin., 63, A (1952), pp. 232-241.
2496 2496
2497 if (nargin != 1 && nargin != 3 && nargin != 4) 2497 if (nargin != 1 && nargin != 3 && nargin != 4)
2498 error ("gallery: 1, 3, or 4 arguments are required for tridiag matrix."); 2498 error ("gallery: 1, 3, or 4 arguments are required for tridiag matrix.");
2499 elseif (nargin == 3) 2499 elseif (nargin == 3)
2500 z = y; 2500 z = y;
2522 T = spdiags ([[x;0] y [0;z]], -1:1, n, n); 2522 T = spdiags ([[x;0] y [0;z]], -1:1, n, n);
2523 endfunction 2523 endfunction
2524 2524
2525 function t = triw (n, alpha = -1, k = n(end) - 1) 2525 function t = triw (n, alpha = -1, k = n(end) - 1)
2526 ## TRIW Upper triangular matrix discussed by Wilkinson and others. 2526 ## TRIW Upper triangular matrix discussed by Wilkinson and others.
2527 ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on 2527 ## TRIW(N, ALPHA, K) is the upper triangular matrix with ones on
2528 ## the diagonal and ALPHAs on the first K >= 0 superdiagonals. 2528 ## the diagonal and ALPHAs on the first K >= 0 superdiagonals.
2529 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2) and 2529 ## N may be a 2-vector, in which case the matrix is N(1)-by-N(2) and
2530 ## upper trapezoidal. 2530 ## upper trapezoidal.
2531 ## Defaults: ALPHA = -1, 2531 ## Defaults: ALPHA = -1,
2532 ## K = N - 1 (full upper triangle). 2532 ## K = N - 1 (full upper triangle).
2533 ## TRIW(N) is a matrix discussed by Kahan, Golub and Wilkinson. 2533 ## TRIW(N) is a matrix discussed by Kahan, Golub and Wilkinson.
2534 ## 2534 ##
2535 ## Ostrowski (1954) shows that 2535 ## Ostrowski (1954) shows that
2536 ## COND(TRIW(N,2)) = COT(PI/(4*N))^2, 2536 ## COND(TRIW(N,2)) = COT(PI/(4*N))^2,
2537 ## and for large ABS(ALPHA), 2537 ## and for large ABS(ALPHA),
2538 ## COND(TRIW(N,ALPHA)) is approximately ABS(ALPHA)^N*SIN(PI/(4*N-2)). 2538 ## COND(TRIW(N,ALPHA)) is approximately ABS(ALPHA)^N*SIN(PI/(4*N-2)).
2539 ## 2539 ##
2540 ## Adding -2^(2-N) to the (N,1) element makes TRIW(N) singular, 2540 ## Adding -2^(2-N) to the (N,1) element makes TRIW(N) singular,
2541 ## as does adding -2^(1-N) to all elements in the first column. 2541 ## as does adding -2^(1-N) to all elements in the first column.
2542 ## 2542 ##
2543 ## References: 2543 ## References:
2544 ## G.H. Golub and J.H. Wilkinson, Ill-conditioned eigensystems and the 2544 ## G.H. Golub and J.H. Wilkinson, Ill-conditioned eigensystems and the
2545 ## computation of the Jordan canonical form, SIAM Review, 2545 ## computation of the Jordan canonical form, SIAM Review,
2546 ## 18(4), 1976, pp. 578-619. 2546 ## 18(4), 1976, pp. 578-619.
2547 ## W. Kahan, Numerical linear algebra, Canadian Math. Bulletin, 2547 ## W. Kahan, Numerical linear algebra, Canadian Math. Bulletin,
2548 ## 9 (1966), pp. 757-801. 2548 ## 9 (1966), pp. 757-801.
2549 ## A.M. Ostrowski, On the spectrum of a one-parametric family of 2549 ## A.M. Ostrowski, On the spectrum of a one-parametric family of
2550 ## matrices, J. Reine Angew. Math., 193 (3/4), 1954, pp. 143-160. 2550 ## matrices, J. Reine Angew. Math., 193 (3/4), 1954, pp. 143-160.
2551 ## J.H. Wilkinson, Singular-value decomposition---basic aspects, 2551 ## J.H. Wilkinson, Singular-value decomposition---basic aspects,
2552 ## in D.A.H. Jacobs, ed., Numerical Software---Needs and Availability, 2552 ## in D.A.H. Jacobs, ed., Numerical Software---Needs and Availability,
2553 ## Academic Press, London, 1978, pp. 109-135. 2553 ## Academic Press, London, 1978, pp. 109-135.
2554 2554
2555 if (nargin < 1 || nargin > 3) 2555 if (nargin < 1 || nargin > 3)
2556 error ("gallery: 1 to 3 arguments are required for triw matrix."); 2556 error ("gallery: 1 to 3 arguments are required for triw matrix.");
2557 elseif (! isnumeric (n) || all (numel (n) != [1 2])) 2557 elseif (! isnumeric (n) || all (numel (n) != [1 2]))
2558 error ("gallery: N must be a 1 or 2 elements vector for triw matrix."); 2558 error ("gallery: N must be a 1 or 2 elements vector for triw matrix.");
2608 end_unwind_protect 2608 end_unwind_protect
2609 2609
2610 endfunction 2610 endfunction
2611 2611
2612 function A = wathen (nx, ny, k = 0) 2612 function A = wathen (nx, ny, k = 0)
2613 ## # WATHEN returns the Wathen matrix. 2613 ## WATHEN returns the Wathen matrix.
2614 ## 2614 ##
2615 ## Discussion: 2615 ## Discussion:
2616 ## 2616 ##
2617 ## The Wathen matrix is a finite element matrix which is sparse. 2617 ## The Wathen matrix is a finite element matrix which is sparse.
2618 ## 2618 ##
2619 ## The entries of the matrix depend in part on a physical quantity 2619 ## The entries of the matrix depend in part on a physical quantity
2620 ## related to density. That density is here assigned random values between 2620 ## related to density. That density is here assigned random values between
2621 ## 0 and 100. 2621 ## 0 and 100.
2622 ## 2622 ##
2623 ## A = WATHEN ( NX, NY ) is a sparse random N-by-N finite element matrix 2623 ## A = WATHEN ( NX, NY ) is a sparse random N-by-N finite element matrix
2624 ## where N = 3*NX*NY + 2*NX + 2*NY + 1. 2624 ## where N = 3*NX*NY + 2*NX + 2*NY + 1.
2625 ## 2625 ##
2626 ## A is the consistent mass matrix for a regular NX-by-NY 2626 ## A is the consistent mass matrix for a regular NX-by-NY
2627 ## grid of 8-node (serendipity) elements in 2 space dimensions. 2627 ## grid of 8-node (serendipity) elements in 2 space dimensions.
2628 ## 2628 ##
2629 ## Here is an illustration for NX = 3, NX = 2: 2629 ## Here is an illustration for NX = 3, NX = 2:
2630 ## 2630 ##
2631 ## 23-24-25-26-27-28-29 2631 ## 23-24-25-26-27-28-29
2632 ## | | | | 2632 ## | | | |
2633 ## 19 20 21 22 2633 ## 19 20 21 22
2634 ## | | | | 2634 ## | | | |
2635 ## 12-13-14-15-16-17-18 2635 ## 12-13-14-15-16-17-18
2636 ## | | | | 2636 ## | | | |
2637 ## 8 9 10 11 2637 ## 8 9 10 11
2638 ## | | | | 2638 ## | | | |
2639 ## 1--2--3--4--5--6--7 2639 ## 1--2--3--4--5--6--7
2640 ## 2640 ##
2641 ## For this example, the total number of nodes is, as expected, 2641 ## For this example, the total number of nodes is, as expected,
2642 ## 2642 ##
2643 ## N = 3 * 3 * 2 + 2 * 2 + 2 * 3 + 1 = 29. 2643 ## N = 3 * 3 * 2 + 2 * 2 + 2 * 3 + 1 = 29.
2644 ## 2644 ##
2645 ## A is symmetric positive definite for any (positive) values of 2645 ## A is symmetric positive definite for any (positive) values of
2646 ## the density, RHO(NX,NY), which is chosen randomly in this routine. 2646 ## the density, RHO(NX,NY), which is chosen randomly in this routine.
2647 ## 2647 ##
2648 ## In particular, if D = DIAG(DIAG(A)), then 2648 ## In particular, if D = DIAG(DIAG(A)), then
2649 ## 0.25 <= EIG(INV(D)*A) <= 4.5 2649 ## 0.25 <= EIG(INV(D)*A) <= 4.5
2650 ## for any positive integers NX and NY and any densities RHO(NX,NY). 2650 ## for any positive integers NX and NY and any densities RHO(NX,NY).
2651 ## 2651 ##
2652 ## A = WATHEN ( NX, NY, 1 ) returns the diagonally scaled matrix. 2652 ## A = WATHEN ( NX, NY, 1 ) returns the diagonally scaled matrix.
2653 ## 2653 ##
2654 ## Modified: 2654 ## Modified:
2655 ## 2655 ##
2656 ## 17 September 2007 2656 ## 17 September 2007
2657 ## 2657 ##
2658 ## Author: 2658 ## Author:
2659 ## 2659 ##
2660 ## Nicholas Higham 2660 ## Nicholas Higham
2661 ## 2661 ##
2662 ## Reference: 2662 ## Reference:
2663 ## 2663 ##
2664 ## Nicholas Higham, 2664 ## Nicholas Higham,
2665 ## Algorithm 694: A Collection of Test Matrices in MATLAB, 2665 ## Algorithm 694: A Collection of Test Matrices in MATLAB,
2666 ## ACM Transactions on Mathematical Software, 2666 ## ACM Transactions on Mathematical Software,
2667 ## Volume 17, Number 3, September 1991, pages 289-305. 2667 ## Volume 17, Number 3, September 1991, pages 289-305.
2668 ## 2668 ##
2669 ## Andrew Wathen, 2669 ## Andrew Wathen,
2670 ## Realistic eigenvalue bounds for the Galerkin mass matrix, 2670 ## Realistic eigenvalue bounds for the Galerkin mass matrix,
2671 ## IMA Journal of Numerical Analysis, 2671 ## IMA Journal of Numerical Analysis,
2672 ## Volume 7, 1987, pages 449-457. 2672 ## Volume 7, 1987, pages 449-457.
2673 ## 2673 ##
2674 ## Parameters: 2674 ## Parameters:
2675 ## 2675 ##
2676 ## Input, integer NX, NY, the number of elements in the X and Y directions 2676 ## Input, integer NX, NY, the number of elements in the X and Y directions
2677 ## of the finite element grid. NX and NY must each be at least 1. 2677 ## of the finite element grid. NX and NY must each be at least 1.
2678 ## 2678 ##
2679 ## Optional input, integer K, is used to request that the diagonally scaled 2679 ## Optional input, integer K, is used to request that the diagonally scaled
2680 ## version of the matrix be returned. This happens if K is specified with 2680 ## version of the matrix be returned. This happens if K is specified with
2681 ## the value 1. 2681 ## the value 1.
2682 ## 2682 ##
2683 ## Output, sparse real A(N,N), the matrix. The dimension N is determined by 2683 ## Output, sparse real A(N,N), the matrix. The dimension N is determined by
2684 ## NX and NY, as described above. A is stored in the MATLAB sparse matrix 2684 ## NX and NY, as described above. A is stored in the MATLAB sparse matrix
2685 ## format. 2685 ## format.
2686 2686
2687 if (nargin < 2 || nargin > 3) 2687 if (nargin < 2 || nargin > 3)
2688 error ("gallery: 2 or 3 arguments are required for wathen matrix."); 2688 error ("gallery: 2 or 3 arguments are required for wathen matrix.");
2689 elseif (! isnumeric (nx) || ! isscalar (nx) || nx < 1) 2689 elseif (! isnumeric (nx) || ! isscalar (nx) || nx < 1)
2690 error ("gallery: NX must be a positive scalar for wathen matrix."); 2690 error ("gallery: NX must be a positive scalar for wathen matrix.");
2744 endif 2744 endif
2745 endfunction 2745 endfunction
2746 2746
2747 function [A, b] = wilk (n) 2747 function [A, b] = wilk (n)
2748 ## WILK Various specific matrices devised/discussed by Wilkinson. 2748 ## WILK Various specific matrices devised/discussed by Wilkinson.
2749 ## [A, b] = WILK(N) is the matrix or system of order N. 2749 ## [A, b] = WILK(N) is the matrix or system of order N.
2750 ## N = 3: upper triangular system Ux=b illustrating inaccurate solution. 2750 ## N = 3: upper triangular system Ux=b illustrating inaccurate solution.
2751 ## N = 4: lower triangular system Lx=b, ill-conditioned. 2751 ## N = 4: lower triangular system Lx=b, ill-conditioned.
2752 ## N = 5: HILB(6)(1:5,2:6)*1.8144. Symmetric positive definite. 2752 ## N = 5: HILB(6)(1:5,2:6)*1.8144. Symmetric positive definite.
2753 ## N = 21: W21+, tridiagonal. Eigenvalue problem. 2753 ## N = 21: W21+, tridiagonal. Eigenvalue problem.
2754 ## 2754 ##
2755 ## References: 2755 ## References:
2756 ## J.H. Wilkinson, Error analysis of direct methods of matrix inversion, 2756 ## J.H. Wilkinson, Error analysis of direct methods of matrix inversion,
2757 ## J. Assoc. Comput. Mach., 8 (1961), pp. 281-330. 2757 ## J. Assoc. Comput. Mach., 8 (1961), pp. 281-330.
2758 ## J.H. Wilkinson, Rounding Errors in Algebraic Processes, Notes on Applied 2758 ## J.H. Wilkinson, Rounding Errors in Algebraic Processes, Notes on Applied
2759 ## Science No. 32, Her Majesty's Stationery Office, London, 1963. 2759 ## Science No. 32, Her Majesty's Stationery Office, London, 1963.
2760 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University 2760 ## J.H. Wilkinson, The Algebraic Eigenvalue Problem, Oxford University
2761 ## Press, 1965. 2761 ## Press, 1965.
2762 2762
2763 if (nargin != 1) 2763 if (nargin != 1)
2764 error ("gallery: 1 argument is required for wilk matrix."); 2764 error ("gallery: 1 argument is required for wilk matrix.");
2765 elseif (! isnumeric (n) || ! isscalar (n)) 2765 elseif (! isnumeric (n) || ! isscalar (n))
2766 error ("gallery: N must be a numeric scalar for wilk matrix."); 2766 error ("gallery: N must be a numeric scalar for wilk matrix.");
2805 endfunction 2805 endfunction
2806 2806
2807 ## NOTE: bandred is part of the Test Matrix Toolbox and is used by randsvd() 2807 ## NOTE: bandred is part of the Test Matrix Toolbox and is used by randsvd()
2808 function A = bandred (A, kl, ku) 2808 function A = bandred (A, kl, ku)
2809 ## BANDRED Band reduction by two-sided unitary transformations. 2809 ## BANDRED Band reduction by two-sided unitary transformations.
2810 ## B = BANDRED(A, KL, KU) is a matrix unitarily equivalent to A 2810 ## B = BANDRED(A, KL, KU) is a matrix unitarily equivalent to A
2811 ## with lower bandwidth KL and upper bandwidth KU 2811 ## with lower bandwidth KL and upper bandwidth KU
2812 ## (i.e. B(i,j) = 0 if i > j+KL or j > i+KU). 2812 ## (i.e. B(i,j) = 0 if i > j+KL or j > i+KU).
2813 ## The reduction is performed using Householder transformations. 2813 ## The reduction is performed using Householder transformations.
2814 ## If KU is omitted it defaults to KL. 2814 ## If KU is omitted it defaults to KL.
2815 ## 2815 ##
2816 ## Called by RANDSVD. 2816 ## Called by RANDSVD.
2817 ## This is a `standard' reduction. Cf. reduction to bidiagonal form 2817 ## This is a `standard' reduction. Cf. reduction to bidiagonal form
2818 ## prior to computing the SVD. This code is a little wasteful in that 2818 ## prior to computing the SVD. This code is a little wasteful in that
2819 ## it computes certain elements which are immediately set to zero! 2819 ## it computes certain elements which are immediately set to zero!
2820 ## 2820 ##
2821 ## Reference: 2821 ## Reference:
2822 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition, 2822 ## G.H. Golub and C.F. Van Loan, Matrix Computations, second edition,
2823 ## Johns Hopkins University Press, Baltimore, Maryland, 1989. 2823 ## Johns Hopkins University Press, Baltimore, Maryland, 1989.
2824 ## Section 5.4.3. 2824 ## Section 5.4.3.
2825 2825
2826 ## Check for special case where order of left/right transformations matters. 2826 ## Check for special case where order of left/right transformations matters.
2827 ## Easiest approach is to work on the transpose, flipping back at the end. 2827 ## Easiest approach is to work on the transpose, flipping back at the end.
2828 flip = false; 2828 flip = false;
2829 if (ku == 0) 2829 if (ku == 0)