{"id":10382,"date":"2023-06-28T12:34:09","date_gmt":"2023-06-28T16:34:09","guid":{"rendered":"https:\/\/blogs.mathworks.com\/cleve\/?p=10382"},"modified":"2023-06-28T18:06:43","modified_gmt":"2023-06-28T22:06:43","slug":"minigallery-sampler-of-matlab-test-matrices","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/cleve\/2023\/06\/28\/minigallery-sampler-of-matlab-test-matrices\/","title":{"rendered":"MiniGallery, Sampler of MATLAB Test Matrices"},"content":{"rendered":"<div class=\"content\"><!--introduction--><p>MATLAB has dozens of test matrices.  Here are a few.<\/p><!--\/introduction--><h3>Contents<\/h3><div><ul><li><a href=\"#2fb5167b-7e82-4227-9f86-2870405cf53c\">Mini_Gallery<\/a><\/li><li><a href=\"#eba25d52-863f-4050-9d5c-28d66c4a102b\">Collections<\/a><\/li><li><a href=\"#66c32842-91ed-4ddf-9f2b-544fc3a88564\">Blogs<\/a><\/li><li><a href=\"#a58fbf40-276b-4c6c-8576-97e02358a317\">Software<\/a><\/li><\/ul><\/div><p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"http:\/\/blogs.mathworks.com\/cleve\/files\/TinyGallery.png\" alt=\"\"> <\/p><h4>Mini_Gallery<a name=\"2fb5167b-7e82-4227-9f86-2870405cf53c\"><\/a><\/h4><div><ul><li>Random. <tt>A = sprand(n,n,0.25)<\/tt>. Random sparse, density = 0.25.<\/li><li>Bucky.  <tt>A = bucky<\/tt>. Sparse connectivity graph of the geodesic dome,      the soccer ball, and the carbon-60 molecule.<\/li><li>Wilkinson. <tt>A = wilkinson(n)<\/tt>. Wn+. Nearly equal double eigenvalues.<\/li><li>Band. <tt>A = triu(tril(A,2),-2)<\/tt>.  Elements near diagonal.<\/li><li>Triangular. <tt>A = triu(A)<\/tt>.  Elements on and above diagonal.<\/li><li>Hessenberg. <tt>A = triu(A,-1)<\/tt>.  Upper triangular plus one subdiagonal.      See <tt>schur<\/tt>.<\/li><li>Permutation. <tt>A = sparse(randperm(n),1:n,1)<\/tt>.  One +1 in each row and      column.<\/li><li>Companion.  <tt>c = charpoly(A); A = [-c(2:end); eye(n-1,n)]<\/tt>.      Traditional companion matrix.<\/li><li>Fiedler.  <tt>c = charpoly(A); A = fiedler(-c(2:end))<\/tt>. Fiedler companion      matrix.<\/li><li>Hankel. <tt>A = flip(gallery('toeppd',n))<\/tt>.  Constant antidiagonals.<\/li><li>Toeplitz. <tt>A = gallery('toeppd',n)<\/tt>.  Constant diagonals.<\/li><li>Magic.  <tt>A = magic(n)<\/tt>.  Magic square.<\/li><\/ul><\/div><h4>Collections<a name=\"eba25d52-863f-4050-9d5c-28d66c4a102b\"><\/a><\/h4><div><ul><li><tt>gallery<\/tt>. Nick Higham and MathWorks, <a href=\"https:\/\/www.mathworks.com\/help\/matlab\/ref\/gallery.html\">https:\/\/www.mathworks.com\/help\/matlab\/ref\/gallery.html<\/a><\/li><li>Anymatrix. Nick Higham and Mantas Mikaitis, <a href=\"https:\/\/nhigham.com\/2021\/11\/09\/anymatrix\">https:\/\/nhigham.com\/2021\/11\/09\/anymatrix<\/a>&gt;<\/li><li>SuiteSparse. Tim Davis, Yifan Hu and Scott Kolodzie, <a href=\"http:\/\/sparse.tamu.edu\">http:\/\/sparse.tamu.edu<\/a><\/li><li>MatrixMarket, NIST, <a href=\"https:\/\/math.nist.gov\/MatrixMarket\">https:\/\/math.nist.gov\/MatrixMarket<\/a>.<\/li><\/ul><\/div><h4>Blogs<a name=\"66c32842-91ed-4ddf-9f2b-544fc3a88564\"><\/a><\/h4><div><ul><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/2012\/11\/05\/magic-squares-part-2-algorithms\/\">https:\/\/blogs.mathworks.com\/cleve\/2012\/11\/05\/magic-squares-part-2-algorithms\/<\/a><\/li><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/2013\/04\/15\/wilkinsons-matrices-2\/\">https:\/\/blogs.mathworks.com\/cleve\/2013\/04\/15\/wilkinsons-matrices-2\/<\/a>.<\/li><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/2013\/12\/23\/fiedler-companion-matrix\/\">https:\/\/blogs.mathworks.com\/cleve\/2013\/12\/23\/fiedler-companion-matrix\/<\/a>.<\/li><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/2021\/05\/12\/bringing-back-the-bucky-ball\/\">https:\/\/blogs.mathworks.com\/cleve\/2021\/05\/12\/bringing-back-the-bucky-ball\/<\/a>.<\/li><\/ul><\/div><h4>Software<a name=\"a58fbf40-276b-4c6c-8576-97e02358a317\"><\/a><\/h4><div><ul><li><a href=\"https:\/\/blogs.mathworks.com\/cleve\/files\/Mini_Gallery.m\">https:\/\/blogs.mathworks.com\/cleve\/files\/Mini_Gallery.m<\/a><\/li><\/ul><\/div><script language=\"JavaScript\"> <!-- \r\n    function grabCode_3ac745ceafba4a469aec48ad4b98c1b4() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='3ac745ceafba4a469aec48ad4b98c1b4 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' 3ac745ceafba4a469aec48ad4b98c1b4';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        copyright = 'Copyright 2023 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add copyright line at the bottom if specified.\r\n        if (copyright.length > 0) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n\r\n        d.title = title + ' (MATLAB code)';\r\n        d.close();\r\n    }   \r\n     --> <\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_3ac745ceafba4a469aec48ad4b98c1b4()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n      the MATLAB code <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; R2023a<br><\/p><\/div><!--\r\n3ac745ceafba4a469aec48ad4b98c1b4 ##### SOURCE BEGIN #####\r\n%% MiniGallery, Sampler of MATLAB Test Matrices\r\n% MATLAB has dozens of test matrices.  Here are a few.\r\n\r\n%%\r\n%\r\n% <<TinyGallery.png>>\r\n%\r\n\r\n%% MiniGallery \r\n% * Random. |A = sprand(n,n,0.25)|. Random sparse, density = 0.25.\r\n% * Bucky.  |A = bucky|. Sparse connectivity graph of the geodesic dome, \r\n%      the soccer ball, and the carbon-60 molecule.\r\n% * Wilkinson. |A = wilkinson(n)|. Wn+. Nearly equal double eigenvalues.\r\n% * Band. |A = triu(tril(A,2),-2)|.  Elements near diagonal.\r\n% * Triangular. |A = triu(A)|.  Elements on and above diagonal.\r\n% * Hessenberg. |A = triu(A,-1)|.  Upper triangular plus one subdiagonal.\r\n%      See |schur|.  \r\n% * Permutation. |A = sparse(randperm(n),1:n,1)|.  One +1 in each row and\r\n%      column.\r\n% * Companion.  |c = charpoly(A); A = [-c(2:end); eye(n-1,n)]|.\r\n%      Traditional companion matrix.\r\n% * Fiedler.  |c = charpoly(A); A = fiedler(-c(2:end))|. Fiedler companion\r\n%      matrix. \r\n% * Hankel. |A = flip(gallery('toeppd',n))|.  Constant antidiagonals.\r\n% * Toeplitz. |A = gallery('toeppd',n)|.  Constant diagonals.\r\n% * Magic.  |A = magic(n)|.  Magic square.\r\n\r\n%% Collections\r\n% * |gallery|. Nick Higham and MathWorks, <https:\/\/www.mathworks.com\/help\/matlab\/ref\/gallery.html>\r\n% * Anymatrix. Nick Higham and Mantas Mikaitis, https:\/\/nhigham.com\/2021\/11\/09\/anymatrix>\r\n% * SuiteSparse. Tim Davis, Yifan Hu and Scott Kolodzie, <http:\/\/sparse.tamu.edu>\r\n% * MatrixMarket, NIST, <https:\/\/math.nist.gov\/MatrixMarket>.\r\n\r\n%% Blogs\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/2012\/11\/05\/magic-squares-part-2-algorithms\/>\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/2013\/04\/15\/wilkinsons-matrices-2\/>.\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/2013\/12\/23\/fiedler-companion-matrix\/>.\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/2021\/05\/12\/bringing-back-the-bucky-ball\/>.\r\n\r\n%% Software\r\n% * <https:\/\/blogs.mathworks.com\/cleve\/files\/MiniGallery.m>\r\n##### SOURCE END ##### 3ac745ceafba4a469aec48ad4b98c1b4\r\n-->","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img src=\"https:\/\/blogs.mathworks.com\/cleve\/files\/fiedler.png\" class=\"img-responsive attachment-post-thumbnail size-post-thumbnail wp-post-image\" alt=\"\" decoding=\"async\" loading=\"lazy\" \/><\/div><!--introduction--><p>MATLAB has dozens of test matrices.  Here are a few.... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/cleve\/2023\/06\/28\/minigallery-sampler-of-matlab-test-matrices\/\">read more >><\/a><\/p>","protected":false},"author":78,"featured_media":10388,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[23,6,16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/10382"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/users\/78"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/comments?post=10382"}],"version-history":[{"count":6,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/10382\/revisions"}],"predecessor-version":[{"id":10424,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/posts\/10382\/revisions\/10424"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media\/10388"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/media?parent=10382"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/categories?post=10382"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/cleve\/wp-json\/wp\/v2\/tags?post=10382"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}