1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094
|
@c DO NOT EDIT! Generated automatically by munge-texi.pl.
@c Copyright (C) 1996-2025 The Octave Project Developers
@c
@c This file is part of Octave.
@c
@c Octave is free software: you can redistribute it and/or modify it
@c under the terms of the GNU General Public License as published by
@c the Free Software Foundation, either version 3 of the License, or
@c (at your option) any later version.
@c
@c Octave is distributed in the hope that it will be useful, but
@c WITHOUT ANY WARRANTY; without even the implied warranty of
@c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@c GNU General Public License for more details.
@c
@c You should have received a copy of the GNU General Public License
@c along with Octave; see the file COPYING. If not, see
@c <https://www.gnu.org/licenses/>.
@node Matrix Manipulation
@chapter Matrix Manipulation
There are a number of functions available for checking to see if the
elements of a matrix meet some condition, and for rearranging the
elements of a matrix. For example, Octave can easily tell you if all
the elements of a matrix are finite, or are less than some specified
value. Octave can also rotate the elements, extract the upper- or
lower-triangular parts, or sort the columns of a matrix.
@menu
* Finding Elements and Checking Conditions::
* Rearranging Matrices::
* Special Utility Matrices::
* Famous Matrices::
@end menu
@node Finding Elements and Checking Conditions
@section Finding Elements and Checking Conditions
The functions @code{any} and @code{all} are useful for determining
whether any or all of the elements of a matrix satisfy some condition.
The @code{find} function is also useful in determining which elements of
a matrix meet a specified condition.
@c any libinterp/corefcn/data.cc
@anchor{XREFany}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{tf} =} any (@var{x})
@deftypefnx {} {@var{tf} =} any (@var{x}, @var{dim})
For a vector argument, return true (logical 1) if any element of the vector
is nonzero.
For a matrix argument, return a row vector of logical ones and zeros with each
element indicating whether any of the elements of the corresponding column of
the matrix are nonzero. For example:
@example
@group
any (eye (2, 4))
@result{} [ 1, 1, 0, 0 ]
@end group
@end example
If the optional argument @var{dim} is supplied, work along dimension @var{dim}.
For example:
@example
@group
any (eye (2, 4), 2)
@result{} [ 1; 1 ]
@end group
@end example
@xseealso{@ref{XREFall,,all}}
@end deftypefn
@c all libinterp/corefcn/data.cc
@anchor{XREFall}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{tf} =} all (@var{x})
@deftypefnx {} {@var{tf} =} all (@var{x}, @var{dim})
For a vector argument, return true (logical 1) if all elements of the vector
are nonzero.
For a matrix argument, return a row vector of logical ones and zeros with each
element indicating whether all of the elements of the corresponding column of
the matrix are nonzero. For example:
@example
@group
all ([2, 3; 1, 0])
@result{} [ 1, 0 ]
@end group
@end example
If the optional argument @var{dim} is supplied, work along dimension @var{dim}.
@xseealso{@ref{XREFany,,any}}
@end deftypefn
Since the comparison operators (@pxref{Comparison Ops}) return matrices
of ones and zeros, it is easy to test a matrix for many things, not just
whether the elements are nonzero. For example,
@example
@group
all (all (rand (5) < 0.9))
@result{} 0
@end group
@end example
@noindent
tests a random 5 by 5 matrix to see if all of its elements are less
than 0.9.
Note that in conditional contexts (like the test clause of @code{if} and
@code{while} statements) Octave treats the test as if you had typed
@code{all (all (condition))}.
@c xor scripts/general/xor.m
@anchor{XREFxor}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{z} =} xor (@var{x}, @var{y})
@deftypefnx {} {@var{z} =} xor (@var{x1}, @var{x2}, @dots{})
Return the @dfn{exclusive or} of @var{x} and @var{y}.
For boolean expressions @var{x} and @var{y},
@code{xor (@var{x}, @var{y})} is true if and only if one of @var{x} or
@var{y} is true. Otherwise, if @var{x} and @var{y} are both true or both
false, @code{xor} returns false.
The truth table for the xor operation is
@multitable @columnfractions 0.41 .044 .06 .042 0.42
@item @tab @var{x} @tab @var{y} @tab @var{z} @tab
@item @tab - @tab - @tab - @tab
@item @tab 0 @tab 0 @tab 0 @tab
@item @tab 1 @tab 0 @tab 1 @tab
@item @tab 0 @tab 1 @tab 1 @tab
@item @tab 1 @tab 1 @tab 0 @tab
@end multitable
If more than two arguments are given the xor operation is applied
cumulatively from left to right:
@example
(@dots{}((x1 XOR x2) XOR x3) XOR @dots{})
@end example
@xseealso{@ref{XREFand,,and}, @ref{XREFor,,or}, @ref{XREFnot,,not}}
@end deftypefn
@c diff libinterp/corefcn/data.cc
@anchor{XREFdiff}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{y} =} diff (@var{x})
@deftypefnx {} {@var{y} =} diff (@var{x}, @var{k})
@deftypefnx {} {@var{y} =} diff (@var{x}, @var{k}, @var{dim})
If @var{x} is a vector of length @math{n}, @w{@code{diff (@var{x})}}@ is the
vector of first differences
@tex
$x_2 - x_1, \ldots{}, x_n - x_{n-1}$.
@end tex
@ifnottex
@var{x}(2) - @var{x}(1), @dots{}, @var{x}(n) - @var{x}(n-1).
@end ifnottex
If @var{x} is a matrix, @w{@code{diff (@var{x})}}@ is the matrix of column
differences along the first non-singleton dimension.
The second argument is optional. If supplied,
@w{@code{diff (@var{x}, @var{k})}}, where @var{k} is a non-negative integer,
returns the @var{k}-th differences. It is possible that @var{k} is larger than
the first non-singleton dimension of the matrix. In this case, @code{diff}
continues to take the differences along the next non-singleton dimension.
The dimension along which to take the difference can be explicitly stated with
the optional variable @var{dim}. In this case the @var{k}-th order differences
are calculated along this dimension. In the case where @var{k} exceeds
@w{@code{size (@var{x}, @var{dim})}}@ an empty matrix is returned.
@xseealso{@ref{XREFsort,,sort}, @ref{XREFmerge,,merge}}
@end deftypefn
@c isinf libinterp/corefcn/mappers.cc
@anchor{XREFisinf}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{tf} =} isinf (@var{x})
Return a logical array which is true where the elements of @var{x} are
infinite and false where they are not.
For example:
@example
@group
isinf ([13, Inf, NA, NaN])
@result{} [ 0, 1, 0, 0 ]
@end group
@end example
@xseealso{@ref{XREFisfinite,,isfinite}, @ref{XREFisnan,,isnan}, @ref{XREFisna,,isna}}
@end deftypefn
@c isnan libinterp/corefcn/mappers.cc
@anchor{XREFisnan}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{tf} =} isnan (@var{x})
Return a logical array which is true where the elements of @var{x} are
NaN values and false where they are not.
NA values are also considered NaN values. For example:
@example
@group
isnan ([13, Inf, NA, NaN])
@result{} [ 0, 0, 1, 1 ]
@end group
@end example
@xseealso{@ref{XREFisna,,isna}, @ref{XREFisinf,,isinf}, @ref{XREFisfinite,,isfinite}}
@end deftypefn
@c isfinite libinterp/corefcn/mappers.cc
@anchor{XREFisfinite}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{tf} =} isfinite (@var{x})
Return a logical array which is true where the elements of @var{x} are
finite values and false where they are not.
For example:
@example
@group
isfinite ([13, Inf, NA, NaN])
@result{} [ 1, 0, 0, 0 ]
@end group
@end example
@xseealso{@ref{XREFisinf,,isinf}, @ref{XREFisnan,,isnan}, @ref{XREFisna,,isna}}
@end deftypefn
@c common_size scripts/general/common_size.m
@anchor{XREFcommon_size}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {[@var{err}, @var{yi}, @dots{}] =} common_size (@var{xi}, @dots{})
Determine if all input arguments are either scalar or of common size.
If true, @var{err} is zero, and @var{yi} is a matrix of the common size
with all entries equal to @var{xi} if this is a scalar or @var{xi}
otherwise. If the inputs cannot be brought to a common size, @var{err} is
1, and @var{yi} is @var{xi}. For example:
@example
@group
[err, a, b] = common_size ([1 2; 3 4], 5)
@result{} err = 0
@result{} a = [ 1, 2; 3, 4 ]
@result{} b = [ 5, 5; 5, 5 ]
@end group
@end example
@noindent
This is useful for implementing functions where arguments can either be
scalars or of common size.
@xseealso{@ref{XREFsize,,size}, @ref{XREFsize_equal,,size_equal}, @ref{XREFnumel,,numel}, @ref{XREFndims,,ndims}}
@end deftypefn
@c find libinterp/corefcn/find.cc
@anchor{XREFfind}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{idx} =} find (@var{x})
@deftypefnx {} {@var{idx} =} find (@var{x}, @var{n})
@deftypefnx {} {@var{idx} =} find (@var{x}, @var{n}, @var{direction})
@deftypefnx {} {[i, j] =} find (@dots{})
@deftypefnx {} {[i, j, v] =} find (@dots{})
Return a vector of indices of nonzero elements of a matrix, as a row if
@var{x} is a row vector or as a column otherwise.
To obtain a single index for each matrix element, Octave pretends that the
columns of a matrix form one long vector (like Fortran arrays are stored).
For example:
@example
@group
find (eye (2))
@result{} [ 1; 4 ]
@end group
@end example
If two inputs are given, @var{n} indicates the maximum number of elements to
find from the beginning of the matrix or vector.
If three inputs are given, @var{direction} should be one of
@qcode{"first"} or @qcode{"last"}, requesting only the first or last
@var{n} indices, respectively. However, the indices are always returned in
ascending order.
If two outputs are requested, @code{find} returns the row and column
indices of nonzero elements of a matrix. For example:
@example
@group
[i, j] = find (2 * eye (2))
@result{} i = [ 1; 2 ]
@result{} j = [ 1; 2 ]
@end group
@end example
If three outputs are requested, @code{find} also returns a vector
containing the nonzero values. For example:
@example
@group
[i, j, v] = find (3 * eye (2))
@result{} i = [ 1; 2 ]
@result{} j = [ 1; 2 ]
@result{} v = [ 3; 3 ]
@end group
@end example
If @var{x} is a multi-dimensional array of size m x n x p x @dots{}, @var{j}
contains the column locations as if @var{x} was flattened into a
two-dimensional matrix of size m x (n + p + @dots{}).
Note that this function is particularly useful for sparse matrices, as
it extracts the nonzero elements as vectors, which can then be used to
create the original matrix. For example:
@example
@group
sz = size (a);
[i, j, v] = find (a);
b = sparse (i, j, v, sz(1), sz(2));
@end group
@end example
@xseealso{@ref{XREFnonzeros,,nonzeros}}
@end deftypefn
@c lookup libinterp/corefcn/lookup.cc
@anchor{XREFlookup}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{idx} =} lookup (@var{table}, @var{y})
@deftypefnx {} {@var{idx} =} lookup (@var{table}, @var{y}, @var{opt})
Lookup values in a @strong{sorted} table.
This function is usually used as a prelude to interpolation.
If table is increasing, of length N and @code{idx = lookup (table, y)}, then
@code{table(idx(i)) <= y(i) < table(idx(i+1))} for all @code{y(i)} within the
table. If @code{y(i) < table(1)} then @code{idx(i)} is 0. If
@code{y(i) >= table(end)} or @code{isnan (y(i))} then @code{idx(i)} is N.
If the table is decreasing, then the tests are reversed. For non-strictly
monotonic tables, empty intervals are always skipped. The result is undefined
if @var{table} is not monotonic, or if @var{table} contains a NaN.
The complexity of the lookup is O(M*log(N)) where M is the size of @var{y}.
In the special case when @var{y} is also sorted, the complexity is
O(min (M*log(N), M+N)).
@var{table} and @var{y} can also be cell arrays of strings (or @var{y} can be a
single string). In this case, string lookup is performed using lexicographical
comparison.
If @var{opts} is specified, it must be a string with letters indicating
additional options.
@table @code
@item m
Match. @code{table(idx(i)) == y(i)} if @code{y(i)} occurs in table;
otherwise, @code{idx(i)} is zero.
@item b
Boolean. @code{idx(i)} is a logical 1 or 0, indicating whether @code{y(i)}
is contained in table or not.
@item l
Left. For numeric lookups the leftmost subinterval shall be extended to
minus infinity (i.e., all indices at least 1).
@item r
Right. For numeric lookups the rightmost subinterval shall be extended to
infinity (i.e., all indices at most N-1).
@end table
@strong{Note}: If @var{table} is not sorted the results from @code{lookup}
will be unpredictable.
@end deftypefn
If you wish to check if a variable exists at all, instead of properties
its elements may have, consult @ref{Status of Variables}.
@node Rearranging Matrices
@section Rearranging Matrices
@c fliplr scripts/general/fliplr.m
@anchor{XREFfliplr}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} fliplr (@var{A})
Flip array left to right.
Return a copy of @var{A} with the order of the columns reversed. In other
words, @var{A} is flipped left-to-right about a vertical axis. For example:
@example
@group
fliplr ([1, 2; 3, 4])
@result{} 2 1
4 3
@end group
@end example
@xseealso{@ref{XREFflipud,,flipud}, @ref{XREFflip,,flip}, @ref{XREFrot90,,rot90}, @ref{XREFrotdim,,rotdim}}
@end deftypefn
@c flipud scripts/general/flipud.m
@anchor{XREFflipud}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} flipud (@var{A})
Flip array upside down.
Return a copy of @var{A} with the order of the rows reversed. In other
words, @var{A} is flipped upside-down about a horizontal axis. For example:
@example
@group
flipud ([1, 2; 3, 4])
@result{} 3 4
1 2
@end group
@end example
@xseealso{@ref{XREFfliplr,,fliplr}, @ref{XREFflip,,flip}, @ref{XREFrot90,,rot90}, @ref{XREFrotdim,,rotdim}}
@end deftypefn
@c flip scripts/general/flip.m
@anchor{XREFflip}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} flip (@var{A})
@deftypefnx {} {@var{B} =} flip (@var{A}, @var{dim})
Return a copy of array @var{A} flipped across dimension @var{dim}.
If @var{dim} is unspecified it defaults to the first non-singleton
dimension.
Examples:
@example
## row vector
flip ([1 2 3 4])
@result{} 4 3 2 1
## column vector
flip ([1; 2; 3; 4])
@result{} 4
3
2
1
## 2-D matrix along dimension 1
flip ([1 2; 3 4])
@result{} 3 4
1 2
## 2-D matrix along dimension 2
flip ([1 2; 3 4], 2)
@result{} 2 1
4 3
@end example
@xseealso{@ref{XREFfliplr,,fliplr}, @ref{XREFflipud,,flipud}, @ref{XREFrot90,,rot90}, @ref{XREFrotdim,,rotdim}, @ref{XREFpermute,,permute}, @ref{XREFtranspose,,transpose}}
@end deftypefn
@c rot90 scripts/general/rot90.m
@anchor{XREFrot90}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} rot90 (@var{A})
@deftypefnx {} {@var{B} =} rot90 (@var{A}, @var{k})
Rotate array by 90 degree increments.
Return a copy of @var{A} with the elements rotated counterclockwise in
90-degree increments.
The second argument is optional, and specifies how many 90-degree rotations
are to be applied (the default value is 1). Negative values of @var{k}
rotate the matrix in a clockwise direction.
For example,
@example
@group
rot90 ([1, 2; 3, 4], -1)
@result{} 3 1
4 2
@end group
@end example
@noindent
rotates the given matrix clockwise by 90 degrees. The following are all
equivalent statements:
@example
@group
rot90 ([1, 2; 3, 4], -1)
rot90 ([1, 2; 3, 4], 3)
rot90 ([1, 2; 3, 4], 7)
@end group
@end example
The rotation is always performed on the plane of the first two dimensions,
i.e., rows and columns. To perform a rotation on any other plane, use
@code{rotdim}.
@xseealso{@ref{XREFrotdim,,rotdim}, @ref{XREFfliplr,,fliplr}, @ref{XREFflipud,,flipud}, @ref{XREFflip,,flip}}
@end deftypefn
@c rotdim scripts/general/rotdim.m
@anchor{XREFrotdim}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} rotdim (@var{A})
@deftypefnx {} {@var{B} =} rotdim (@var{A}, @var{n})
@deftypefnx {} {@var{B} =} rotdim (@var{A}, @var{n}, @var{plane})
Return a copy of @var{A} with the elements rotated counterclockwise in
90-degree increments.
The second argument @var{n} is optional, and specifies how many 90-degree
rotations are to be applied (the default value is 1). Negative values of
@var{n} rotate the matrix in a clockwise direction.
The third argument is also optional and defines the plane of the rotation.
If present, @var{plane} is a two element vector containing two different
valid dimensions of the matrix. When @var{plane} is not given the first two
non-singleton dimensions are used.
For example,
@example
@group
rotdim ([1, 2; 3, 4], -1, [1, 2])
@result{} 3 1
4 2
@end group
@end example
@noindent
rotates the given matrix clockwise by 90 degrees. The following are all
equivalent statements:
@example
@group
rotdim ([1, 2; 3, 4], -1, [1, 2])
rotdim ([1, 2; 3, 4], 3, [1, 2])
rotdim ([1, 2; 3, 4], 7, [1, 2])
@end group
@end example
@xseealso{@ref{XREFrot90,,rot90}, @ref{XREFfliplr,,fliplr}, @ref{XREFflipud,,flipud}, @ref{XREFflip,,flip}}
@end deftypefn
@c cat libinterp/corefcn/data.cc
@anchor{XREFcat}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{A} =} cat (@var{dim}, @var{array1}, @var{array2}, @dots{}, @var{arrayN})
Return the concatenation of N-D array objects, @var{array1}, @var{array2},
@dots{}, @var{arrayN} along dimension @var{dim}.
@example
@group
A = ones (2, 2);
B = zeros (2, 2);
cat (2, A, B)
@result{} 1 1 0 0
1 1 0 0
@end group
@end example
Alternatively, we can concatenate @var{A} and @var{B} along the second
dimension in the following way:
@example
@group
[A, B]
@end group
@end example
@var{dim} can be larger than the dimensions of the N-D array objects and the
result will thus have @var{dim} dimensions as the following example shows:
@example
@group
cat (4, ones (2, 2), zeros (2, 2))
@result{} ans(:,:,1,1) =
1 1
1 1
ans(:,:,1,2) =
0 0
0 0
@end group
@end example
@xseealso{@ref{XREFhorzcat,,horzcat}, @ref{XREFvertcat,,vertcat}}
@end deftypefn
@c horzcat libinterp/corefcn/data.cc
@anchor{XREFhorzcat}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{A} =} horzcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
Return the horizontal concatenation of N-D array objects, @var{array1},
@var{array2}, @dots{}, @var{arrayN} along dimension 2.
Arrays may also be concatenated horizontally using the syntax for creating
new matrices. For example:
@example
@var{A} = [ @var{array1}, @var{array2}, @dots{} ]
@end example
This syntax is slightly more efficient because the Octave parser can
concatenate the arrays without the overhead of a function call.
@xseealso{@ref{XREFcat,,cat}, @ref{XREFvertcat,,vertcat}}
@end deftypefn
@c vertcat libinterp/corefcn/data.cc
@anchor{XREFvertcat}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{A} =} vertcat (@var{array1}, @var{array2}, @dots{}, @var{arrayN})
Return the vertical concatenation of N-D array objects, @var{array1},
@var{array2}, @dots{}, @var{arrayN} along dimension 1.
Arrays may also be concatenated vertically using the syntax for creating
new matrices. For example:
@example
@var{A} = [ @var{array1}; @var{array2}; @dots{} ]
@end example
This syntax is slightly more efficient because the Octave parser can
concatenate the arrays without the overhead of a function call.
@xseealso{@ref{XREFcat,,cat}, @ref{XREFhorzcat,,horzcat}}
@end deftypefn
@c permute libinterp/corefcn/data.cc
@anchor{XREFpermute}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} permute (@var{A}, @var{perm})
Return the generalized transpose for an N-D array object @var{A}.
The permutation vector @var{perm} must contain the elements
@w{@code{1:ndims (A)}}@ (in any order, but each element must appear only
once). The @var{N}th dimension of @var{A} gets remapped to dimension
@code{@var{PERM}(@var{N})}. For example:
@example
@group
@var{x} = zeros ([2, 3, 5, 7]);
size (@var{x})
@result{} 2 3 5 7
size (permute (@var{x}, [2, 1, 3, 4]))
@result{} 3 2 5 7
size (permute (@var{x}, [1, 3, 4, 2]))
@result{} 2 5 7 3
## The identity permutation
size (permute (@var{x}, [1, 2, 3, 4]))
@result{} 2 3 5 7
@end group
@end example
@xseealso{@ref{XREFipermute,,ipermute}}
@end deftypefn
@c ipermute libinterp/corefcn/data.cc
@anchor{XREFipermute}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{A} =} ipermute (@var{B}, @var{iperm})
The inverse of the @code{permute} function.
The expression
@example
ipermute (permute (A, perm), perm)
@end example
@noindent
returns the original array @var{A}.
@xseealso{@ref{XREFpermute,,permute}}
@end deftypefn
@c reshape libinterp/corefcn/data.cc
@anchor{XREFreshape}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} reshape (@var{A}, @var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{B} =} reshape (@var{A}, [@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{B} =} reshape (@var{A}, @dots{}, [], @dots{})
@deftypefnx {} {@var{B} =} reshape (@var{A}, @var{size})
Return a matrix with the specified dimensions (@var{m}, @var{n}, @dots{})
whose elements are taken from the matrix @var{A}.
The elements of the matrix are accessed in column-major order (like Fortran
arrays are stored).
The following code demonstrates reshaping a 1x4 row vector into a 2x2 square
matrix.
@example
@group
reshape ([1, 2, 3, 4], 2, 2)
@result{} 1 3
2 4
@end group
@end example
@noindent
Note that the total number of elements in the original matrix
(@code{prod (size (@var{A}))}) must match the total number of elements
in the new matrix (@code{prod ([@var{m} @var{n} @dots{}])}).
A single dimension of the return matrix may be left unspecified and Octave
will determine its size automatically. An empty matrix ([]) is used to flag
the unspecified dimension.
@xseealso{@ref{XREFresize,,resize}, @ref{XREFvec,,vec}, @ref{XREFpostpad,,postpad}, @ref{XREFcat,,cat}, @ref{XREFsqueeze,,squeeze}}
@end deftypefn
@c resize libinterp/corefcn/data.cc
@anchor{XREFresize}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} resize (@var{A}, @var{m})
@deftypefnx {} {@var{B} =} resize (@var{A}, @var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{B} =} resize (@var{A}, [@var{m} @var{n} @dots{}])
Resize @var{A} cutting off elements as necessary.
In the result, element with certain indices is equal to the corresponding
element of @var{A} if the indices are within the bounds of @var{A}; otherwise,
the element is set to zero.
In other words, the statement
@example
B = resize (A, dv)
@end example
@noindent
is equivalent to the following code:
@example
@group
B = zeros (dv, class (A));
sz = min (dv, size (A));
for i = 1:length (sz)
idx@{i@} = 1:sz(i);
endfor
B(idx@{:@}) = A(idx@{:@});
@end group
@end example
@noindent
but is performed more efficiently.
If only @var{m} is supplied, and it is a scalar, the dimension of the result is
@var{m}-by-@var{m}. If @var{m}, @var{n}, @dots{} are all scalars, then the
dimensions of the result are @var{m}-by-@var{n}-by-@enddots{} If given a vector
as input, then the dimensions of the result are given by the elements of that
vector.
An object can be resized to more dimensions than it has; in such case the
missing dimensions are assumed to be 1. Resizing an object to fewer dimensions
is not possible.
@xseealso{@ref{XREFreshape,,reshape}, @ref{XREFpostpad,,postpad}, @ref{XREFprepad,,prepad}, @ref{XREFcat,,cat}}
@end deftypefn
@c circshift scripts/general/circshift.m
@anchor{XREFcircshift}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{y} =} circshift (@var{x}, @var{n})
@deftypefnx {} {@var{y} =} circshift (@var{x}, @var{n}, @var{dim})
Circularly shift the values of the array @var{x}.
@var{n} must be a vector of integers no longer than the number of dimensions
in @var{x}. The values of @var{n} can be either positive or negative, which
determines the direction in which the values of @var{x} are shifted. If an
element of @var{n} is zero, then the corresponding dimension of @var{x} will
not be shifted. If @var{n} is a scalar and no @var{dim} is specified then
the shift is applied to the first non-singular dimension.
If a scalar @var{dim} is given then operate along the specified dimension.
In this case @var{n} must be a scalar as well.
Examples:
@example
x = [1, 2, 3;
4, 5, 6;
7, 8, 9];
## positive shift on rows (1st non-singular dim)
circshift (x, 1)
@result{}
7 8 9
1 2 3
4 5 6
## negative shift on rows (1st non-singular dim)
circshift (x, -2)
@result{}
7 8 9
1 2 3
4 5 6
## no shift of rows, shift columns by 1 (2nd dimension)
circshift (x, [0,1])
@result{}
3 1 2
6 4 5
9 7 8
## shift columns (2nd dimension)
circshift (x, 1, 2)
@result{}
3 1 2
6 4 5
9 7 8
@end example
@xseealso{@ref{XREFpermute,,permute}, @ref{XREFipermute,,ipermute}, @ref{XREFshiftdim,,shiftdim}}
@end deftypefn
@c shiftdim scripts/general/shiftdim.m
@anchor{XREFshiftdim}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{y} =} shiftdim (@var{x}, @var{n})
@deftypefnx {} {[@var{y}, @var{ns}] =} shiftdim (@var{x})
Shift the dimensions of @var{x} by @var{n}, where @var{n} must be
an integer scalar.
When @var{n} is positive, the dimensions of @var{x} are shifted to the left,
with the leading dimensions circulated to the end. If @var{n} is negative,
then the dimensions of @var{x} are shifted to the right, with @var{n}
leading singleton dimensions added.
Called with a single argument, @code{shiftdim}, removes the leading
singleton dimensions, returning the number of dimensions removed in the
second output argument @var{ns}.
For example:
@example
@group
x = ones (1, 2, 3);
size (shiftdim (x, -1))
@result{} 1 1 2 3
size (shiftdim (x, 1))
@result{} 2 3
[b, ns] = shiftdim (x)
@result{} b =
1 1 1
1 1 1
@result{} ns = 1
@end group
@end example
@xseealso{@ref{XREFreshape,,reshape}, @ref{XREFpermute,,permute}, @ref{XREFipermute,,ipermute}, @ref{XREFcircshift,,circshift}, @ref{XREFsqueeze,,squeeze}}
@end deftypefn
@c sort libinterp/corefcn/data.cc
@anchor{XREFsort}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {[@var{s}, @var{i}] =} sort (@var{x})
@deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim})
@deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{mode})
@deftypefnx {} {[@var{s}, @var{i}] =} sort (@var{x}, @var{dim}, @var{mode})
Return a copy of @var{x} with the elements arranged in increasing order.
For matrices, @code{sort} orders the elements within columns
For example:
@example
@group
sort ([1, 2; 2, 3; 3, 1])
@result{} 1 1
2 2
3 3
@end group
@end example
If the optional argument @var{dim} is given, then the matrix is sorted
along the dimension defined by @var{dim}. The optional argument @var{mode}
defines the order in which the values will be sorted. Valid values of
@var{mode} are @qcode{"ascend"} or @qcode{"descend"}.
The @code{sort} function may also be used to produce a matrix
containing the original row indices of the elements in the sorted
matrix. For example:
@example
@group
[s, i] = sort ([1, 2; 2, 3; 3, 1])
@result{} s = 1 1
2 2
3 3
@result{} i = 1 3
2 1
3 2
@end group
@end example
For equal elements, the indices are such that equal elements are listed
in the order in which they appeared in the original list.
Sorting of complex entries is done first by magnitude
(@w{@code{abs (@var{z})}})@ and for any ties by phase angle
(@w{@code{angle (z)}}). For example:
@example
@group
sort ([1+i; 1; 1-i])
@result{} 1 + 0i
1 - 1i
1 + 1i
@end group
@end example
NaN values are treated as being greater than any other value and are sorted
to the end of the list.
The @code{sort} function may also be used to sort strings and cell arrays
of strings, in which case ASCII dictionary order (uppercase 'A' precedes
lowercase 'a') of the strings is used.
The algorithm used in @code{sort} is optimized for the sorting of partially
ordered lists.
@xseealso{@ref{XREFsortrows,,sortrows}, @ref{XREFissorted,,issorted}}
@end deftypefn
@c sortrows scripts/general/sortrows.m
@anchor{XREFsortrows}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {[@var{s}, @var{i}] =} sortrows (@var{A})
@deftypefnx {} {[@var{s}, @var{i}] =} sortrows (@var{A}, @var{c})
Sort the rows of the matrix @var{A} according to the order of the columns
specified in @var{c}.
By default (@var{c} omitted, or a particular column unspecified in @var{c})
an ascending sort order is used. However, if elements of @var{c} are
negative then the corresponding column is sorted in descending order. If
the elements of @var{A} are strings then a lexicographical sort is used.
Example: sort by column 2 in descending order, then 3 in ascending order
@example
@group
x = [ 7, 1, 4;
8, 3, 5;
9, 3, 6 ];
sortrows (x, [-2, 3])
@result{} 8 3 5
9 3 6
7 1 4
@end group
@end example
@xseealso{@ref{XREFsort,,sort}}
@end deftypefn
@c issorted libinterp/corefcn/data.cc
@anchor{XREFissorted}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{tf} =} issorted (@var{A})
@deftypefnx {} {@var{tf} =} issorted (@var{A}, @var{mode})
@deftypefnx {} {@var{tf} =} issorted (@var{A}, "rows", @var{mode})
Return true if the vector @var{A} is sorted according to @var{mode}, which
may be either @qcode{"ascend"}, @qcode{"descend"}, @qcode{"either"}, or
@qcode{"monotonic"} (@qcode{"either"} and @qcode{"monotonic"} are
equivalent).
By default, @var{mode} is @qcode{"ascend"}. NaNs are treated in the same
manner as @code{sort}.
If the optional argument @qcode{"rows"} is supplied, check whether the matrix
is sorted by rows as output by the function @code{sortrows} (with no options).
This function does not support sparse matrices.
@xseealso{@ref{XREFsort,,sort}, @ref{XREFsortrows,,sortrows}}
@end deftypefn
@c nth_element libinterp/corefcn/data.cc
@anchor{XREFnth_element}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{nel} =} nth_element (@var{x}, @var{n})
@deftypefnx {} {@var{nel} =} nth_element (@var{x}, @var{n}, @var{dim})
Select the n-th smallest element of a vector, using the ordering defined by
@code{sort}.
The result is equivalent to @code{sort(@var{x})(@var{n})}.
@var{n} can also be a contiguous range, either ascending @code{l:u}
or descending @code{u:-1:l}, in which case a range of elements is returned.
If @var{x} is an array, @code{nth_element} operates along the dimension
defined by @var{dim}, or the first non-singleton dimension if @var{dim} is
not given.
Programming Note: nth_element encapsulates the C++ standard library
algorithms nth_element and partial_sort. On average, the complexity of the
operation is O(M*log(K)), where @w{@code{M = size (@var{x}, @var{dim})}}@ and
@w{@code{K = length (@var{n})}}. This function is intended for cases where
the ratio K/M is small; otherwise, it may be better to use @code{sort}.
@xseealso{@ref{XREFsort,,sort}, @ref{XREFmin,,min}, @ref{XREFmax,,max}}
@end deftypefn
@c tril libinterp/corefcn/tril.cc
@anchor{XREFtril}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{A_LO} =} tril (@var{A})
@deftypefnx {} {@var{A_LO} =} tril (@var{A}, @var{k})
@deftypefnx {} {@var{A_LO} =} tril (@var{A}, @var{k}, @var{pack})
Return a new matrix formed by extracting the lower triangular part of the
matrix @var{A}, and setting all other elements to zero.
The optional second argument specifies how many diagonals above or below the
main diagonal should also be set to zero. The default value of @var{k} is
zero which includes the main diagonal as part of the result. If the value of
@var{k} is a nonzero integer then the selection of elements starts at an offset
of @var{k} diagonals above the main diagonal for positive @var{k} or below the
main diagonal for negative @var{k}. The absolute value of @var{k} may not be
greater than the number of subdiagonals or superdiagonals.
Example 1 : exclude main diagonal
@example
@group
tril (ones (3), -1)
@result{} 0 0 0
1 0 0
1 1 0
@end group
@end example
@noindent
Example 2 : include first superdiagonal
@example
@group
tril (ones (3), 1)
@result{} 1 1 0
1 1 1
1 1 1
@end group
@end example
If the optional third argument @qcode{"pack"} is given then the extracted
elements are not inserted into a matrix, but instead stacked column-wise one
above another, and returned as a column vector.
@xseealso{@ref{XREFtriu,,triu}, @ref{XREFistril,,istril}, @ref{XREFdiag,,diag}}
@end deftypefn
@c triu libinterp/corefcn/tril.cc
@anchor{XREFtriu}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{A_UP} =} triu (@var{A})
@deftypefnx {} {@var{A_UP} =} triu (@var{A}, @var{k})
@deftypefnx {} {@var{A_UP} =} triu (@var{A}, @var{k}, @var{pack})
Return a new matrix formed by extracting the upper triangular part of the
matrix @var{A}, and setting all other elements to zero.
The optional second argument specifies how many diagonals above or below the
main diagonal should also be set to zero. The default value of @var{k} is
zero which includes the main diagonal as part of the result. If the value of
@var{k} is a nonzero integer then the selection of elements starts at an offset
of @var{k} diagonals above the main diagonal for positive @var{k} or below the
main diagonal for negative @var{k}. The absolute value of @var{k} may not be
greater than the number of subdiagonals or superdiagonals.
Example 1 : exclude main diagonal
@example
@group
triu (ones (3), 1)
@result{} 0 1 1
0 0 1
0 0 0
@end group
@end example
@noindent
Example 2 : include first subdiagonal
@example
@group
triu (ones (3), -1)
@result{} 1 1 1
1 1 1
0 1 1
@end group
@end example
If the optional third argument @qcode{"pack"} is given then the extracted
elements are not inserted into a matrix, but instead stacked column-wise one
above another, and returned as a column vector.
@xseealso{@ref{XREFtril,,tril}, @ref{XREFistriu,,istriu}, @ref{XREFdiag,,diag}}
@end deftypefn
@c vec libinterp/corefcn/data.cc
@anchor{XREFvec}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{v} =} vec (@var{x})
@deftypefnx {} {@var{v} =} vec (@var{x}, @var{dim})
Return the vector obtained by stacking the columns of the matrix @var{x}
one above the other.
Without @var{dim} this is equivalent to @code{@var{x}(:)}.
If @var{dim} is supplied, the dimensions of @var{v} are set to @var{dim}
with all elements along the last dimension. This is equivalent to
@code{shiftdim (@var{x}(:), 1-@var{dim})}.
@xseealso{@ref{XREFvech,,vech}, @ref{XREFresize,,resize}, @ref{XREFcat,,cat}}
@end deftypefn
@c vech scripts/linear-algebra/vech.m
@anchor{XREFvech}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{v} =} vech (@var{x})
Return the vector obtained by eliminating all superdiagonal elements of
the square matrix @var{x} and stacking the result one column above the
other.
This has uses in matrix calculus where the underlying matrix is symmetric
and it would be pointless to keep values above the main diagonal.
@xseealso{@ref{XREFvec,,vec}}
@end deftypefn
@c prepad scripts/general/prepad.m
@anchor{XREFprepad}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} prepad (@var{A}, @var{l})
@deftypefnx {} {@var{B} =} prepad (@var{A}, @var{l}, @var{c})
@deftypefnx {} {@var{B} =} prepad (@var{A}, @var{l}, @var{c}, @var{dim})
Prepend the scalar value @var{c} to the vector @var{A} until it is of length
@var{l}. If @var{c} is not given, a value of 0 is used.
If @code{length (@var{A}) > @var{l}}, elements from the beginning of @var{A}
are removed until a vector of length @var{l} is obtained.
If @var{A} is a matrix, elements are prepended or removed from each row.
If the optional argument @var{dim} is given, operate along this dimension.
If @var{dim} is larger than the dimensions of @var{A}, the result will have
@var{dim} dimensions.
@xseealso{@ref{XREFpostpad,,postpad}, @ref{XREFcat,,cat}, @ref{XREFresize,,resize}}
@end deftypefn
@c postpad scripts/general/postpad.m
@anchor{XREFpostpad}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} postpad (@var{A}, @var{l})
@deftypefnx {} {@var{B} =} postpad (@var{A}, @var{l}, @var{c})
@deftypefnx {} {@var{B} =} postpad (@var{A}, @var{l}, @var{c}, @var{dim})
Append the scalar value @var{c} to the vector @var{A} until it is of length
@var{l}. If @var{c} is not given, a value of 0 is used.
If @code{length (@var{A}) > @var{l}}, elements from the end of @var{A} are
removed until a vector of length @var{l} is obtained.
If @var{A} is a matrix, elements are appended or removed from each row.
If the optional argument @var{dim} is given, operate along this dimension.
If @var{dim} is larger than the dimensions of @var{A}, the result will have
@var{dim} dimensions.
@xseealso{@ref{XREFprepad,,prepad}, @ref{XREFcat,,cat}, @ref{XREFresize,,resize}}
@end deftypefn
@c diag libinterp/corefcn/data.cc
@anchor{XREFdiag}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{M} =} diag (@var{v})
@deftypefnx {} {@var{M} =} diag (@var{v}, @var{k})
@deftypefnx {} {@var{M} =} diag (@var{v}, @var{m}, @var{n})
@deftypefnx {} {@var{v} =} diag (@var{M})
@deftypefnx {} {@var{v} =} diag (@var{M}, @var{k})
Return a diagonal matrix with vector @var{v} on diagonal @var{k}.
The second argument is optional. If it is positive, the vector is placed on
the @var{k}-th superdiagonal. If it is negative, it is placed on the
@var{-k}-th subdiagonal. The default value of @var{k} is 0, and the vector
is placed on the main diagonal. For example:
@example
@group
diag ([1, 2, 3], 1)
@result{} 0 1 0 0
0 0 2 0
0 0 0 3
0 0 0 0
@end group
@end example
@noindent
The 3-input form returns a diagonal matrix with vector @var{v} on the main
diagonal and the resulting matrix being of size @var{m} rows x @var{n}
columns.
Given a matrix argument, instead of a vector, @code{diag} extracts the
@var{k}-th diagonal of the matrix.
@end deftypefn
@c blkdiag scripts/general/blkdiag.m
@anchor{XREFblkdiag}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{M} =} blkdiag (@var{A}, @var{B}, @var{C}, @dots{})
Build a block diagonal matrix from @var{A}, @var{B}, @var{C}, @enddots{}
All arguments must be numeric and either two-dimensional matrices or
scalars. If any argument is of type sparse, the output will also be sparse.
@xseealso{@ref{XREFdiag,,diag}, @ref{XREFhorzcat,,horzcat}, @ref{XREFvertcat,,vertcat}, @ref{XREFsparse,,sparse}}
@end deftypefn
@node Special Utility Matrices
@section Special Utility Matrices
@c eye libinterp/corefcn/data.cc
@anchor{XREFeye}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{I} =} eye (@var{n})
@deftypefnx {} {@var{I} =} eye (@var{m}, @var{n})
@deftypefnx {} {@var{I} =} eye ([@var{m} @var{n}])
@deftypefnx {} {@var{I} =} eye (@dots{}, @var{class})
Return an identity matrix.
If invoked with a single scalar argument @var{n}, return a square
@nospell{NxN} identity matrix.
If supplied two scalar arguments (@var{m}, @var{n}), @code{eye} takes them
to be the number of rows and columns. If given a vector with two elements,
@code{eye} uses the values of the elements as the number of rows and
columns, respectively. For example:
@example
@group
eye (3)
@result{} 1 0 0
0 1 0
0 0 1
@end group
@end example
The following expressions all produce the same result:
@example
@group
eye (2)
@equiv{}
eye (2, 2)
@equiv{}
eye (size ([1, 2; 3, 4]))
@end group
@end example
The optional argument @var{class}, allows @code{eye} to return an array of
the specified type, like
@example
val = zeros (n,m, "uint8")
@end example
Calling @code{eye} with no arguments is equivalent to calling it with an
argument of 1. Any negative dimensions are treated as zero. These odd
definitions are for compatibility with @sc{matlab}.
@xseealso{@ref{XREFspeye,,speye}, @ref{XREFones,,ones}, @ref{XREFzeros,,zeros}}
@end deftypefn
@c ones libinterp/corefcn/data.cc
@anchor{XREFones}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{val} =} ones (@var{n})
@deftypefnx {} {@var{val} =} ones (@var{m}, @var{n})
@deftypefnx {} {@var{val} =} ones (@var{m}, @var{n}, @var{k}, @dots{})
@deftypefnx {} {@var{val} =} ones ([@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{val} =} ones (@dots{}, "like", @var{var})
@deftypefnx {} {@var{val} =} ones (@dots{}, @var{class})
Return a matrix or N-dimensional array whose elements are all 1.
If invoked with a single scalar integer argument @var{n}, return a square
@nospell{NxN} matrix.
If invoked with two or more scalar integer arguments, or a vector of integer
values, return an array with the given dimensions.
To create a constant matrix whose values are all the same use an expression
such as
@example
val_matrix = val * ones (m, n)
@end example
If a variable @var{var} is specified after @qcode{"like"}, the output @var{val}
will have the same data type, complexity, and sparsity as @var{var}.
The optional argument @var{class} specifies the class of the return array
and defaults to double. For example:
@example
val = ones (m,n, "uint8")
@end example
@xseealso{@ref{XREFzeros,,zeros}}
@end deftypefn
@c zeros libinterp/corefcn/data.cc
@anchor{XREFzeros}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{val} =} zeros (@var{n})
@deftypefnx {} {@var{val} =} zeros (@var{m}, @var{n})
@deftypefnx {} {@var{val} =} zeros (@var{m}, @var{n}, @var{k}, @dots{})
@deftypefnx {} {@var{val} =} zeros ([@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{val} =} zeros (@dots{}, "like", @var{var})
@deftypefnx {} {@var{val} =} zeros (@dots{}, @var{class})
Return a matrix or N-dimensional array whose elements are all 0.
If invoked with a single scalar integer argument, return a square
@nospell{NxN} matrix.
If invoked with two or more scalar integer arguments, or a vector of integer
values, return an array with the given dimensions.
If a variable @var{var} is specified after @qcode{"like"}, the output @var{val}
will have the same data type, complexity, and sparsity as @var{var}.
The optional argument @var{class} specifies the class of the return array
and defaults to double. For example:
@example
val = zeros (m,n, "uint8")
@end example
@xseealso{@ref{XREFones,,ones}}
@end deftypefn
@c repmat scripts/general/repmat.m
@anchor{XREFrepmat}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{B} =} repmat (@var{A}, @var{m})
@deftypefnx {} {@var{B} =} repmat (@var{A}, @var{m}, @var{n})
@deftypefnx {} {@var{B} =} repmat (@var{A}, @var{m}, @var{n}, @var{p} @dots{})
@deftypefnx {} {@var{B} =} repmat (@var{A}, [@var{m} @var{n}])
@deftypefnx {} {@var{B} =} repmat (@var{A}, [@var{m} @var{n} @var{p} @dots{}])
Repeat matrix or N-D array.
Form a block matrix of size @var{m} by @var{n}, with a copy of matrix
@var{A} as each element.
If @var{n} is not specified, form an @var{m} by @var{m} block matrix. For
copying along more than two dimensions, specify the number of times to copy
across each dimension @var{m}, @var{n}, @var{p}, @dots{}, in a vector in the
second argument.
@xseealso{@ref{XREFbsxfun,,bsxfun}, @ref{XREFkron,,kron}, @ref{XREFrepelems,,repelems}}
@end deftypefn
@c repelems libinterp/corefcn/data.cc
@anchor{XREFrepelems}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{y} =} repelems (@var{x}, @var{r})
Construct a vector of repeated elements from @var{x}.
@var{r} is a 2x@var{N} integer matrix specifying which elements to repeat
and how often to repeat each element. Entries in the first row,
@var{r}(1,j), select an element to repeat. The corresponding entry in the
second row, @var{r}(2,j), specifies the repeat count. If @var{x} is a
matrix then the columns of @var{x} are imagined to be stacked on top of
each other for purposes of the selection index. A row vector is always
returned.
Conceptually the result is calculated as follows:
@example
@group
y = [];
for i = 1:columns (@var{r})
y = [y, @var{x}(@var{r}(1,i)*ones(1, @var{r}(2,i)))];
endfor
@end group
@end example
@xseealso{@ref{XREFrepmat,,repmat}, @ref{XREFcat,,cat}}
@end deftypefn
@c repelem scripts/general/repelem.m
@anchor{XREFrepelem}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{xxx} =} repelem (@var{x}, @var{R})
@deftypefnx {} {@var{xxx} =} repelem (@var{x}, @var{R_1}, @dots{}, @var{R_n})
Construct an array of repeated elements from @var{x} and repeat instructions
@var{R_1}, @enddots{}
@var{x} must be a scalar, vector, or N-dimensional array.
A repeat instruction @var{R_j} must either be a scalar or a vector. If the
instruction is a scalar then each component of @var{x} in dimension @var{j}
is repeated @var{R_j} times. If the instruction is a vector then it must
have the same number of elements as the corresponding dimension @var{j} of
@var{x}. In this case, the @var{k}th component of dimension @var{j} is
repeated @code{@var{R_j}(@var{k})} times.
If @var{x} is a scalar or vector then @code{repelem} may be called with just
a single repeat instruction @var{R} and @code{repelem} will return a vector
with the same orientation as the input.
If @var{x} is a matrix then at least two @var{R_j}s must be specified.
Note: Using @code{repelem} with a vector @var{x} and a vector for @var{R_j}
is equivalent to Run Length Decoding.
Examples:
@example
@group
A = [1 2 3 4 5];
B = [2 1 0 1 2];
repelem (A, B)
@result{} 1 1 2 4 5 5
@end group
@end example
@example
@group
A = magic (3)
@result{} A =
8 1 6
3 5 7
4 9 2
B1 = [1 2 3];
B2 = 2;
repelem (A, B1, B2)
@result{} 8 8 1 1 6 6
3 3 5 5 7 7
3 3 5 5 7 7
4 4 9 9 2 2
4 4 9 9 2 2
4 4 9 9 2 2
@end group
@end example
More @var{R_j} may be specified than the number of dimensions of @var{x}.
Any excess @var{R_j} must be scalars (because @var{x}'s size in those
dimensions is only 1), and @var{x} will be replicated in those dimensions
accordingly.
@example
@group
A = [1 2 3 4 5];
B1 = 2;
B2 = [2 1 3 0 2];
B3 = 3;
repelem (A, B1, B2, B3)
@result{} ans(:,:,1) =
1 1 2 3 3 3 5 5
1 1 2 3 3 3 5 5
ans(:,:,2) =
1 1 2 3 3 3 5 5
1 1 2 3 3 3 5 5
ans(:,:,3) =
1 1 2 3 3 3 5 5
1 1 2 3 3 3 5 5
@end group
@end example
@var{R_j} must be specified in order. A placeholder of 1 may be used for
dimensions which do not need replication.
@example
@group
repelem ([-1, 0; 0, 1], 1, 2, 1, 2)
@result{} ans(:,:,1,1) =
-1 -1 0 0
0 0 1 1
ans(:,:,1,2) =
-1 -1 0 0
0 0 1 1
@end group
@end example
If fewer @var{R_j} are given than the number of dimensions in @var{x},
@code{repelem} will assume @var{R_j} is 1 for those dimensions.
@example
A = cat (3, [-1 0; 0 1], [-1 0; 0 1])
@result{} ans(:,:,1) =
-1 0
0 1
ans(:,:,2) =
-1 0
0 1
repelem (A,2,3)
@result{} ans(:,:,1) =
-1 -1 -1 0 0 0
-1 -1 -1 0 0 0
0 0 0 1 1 1
0 0 0 1 1 1
ans(:,:,2) =
-1 -1 -1 0 0 0
-1 -1 -1 0 0 0
0 0 0 1 1 1
0 0 0 1 1 1
@end example
@code{repelem} preserves the class of @var{x}, and works with strings,
cell arrays, NA, and NAN inputs. If any @var{R_j} is 0 the output will
be an empty array.
@example
@group
repelem ("Octave", 2, 3)
@result{} OOOccctttaaavvveee
OOOccctttaaavvveee
repelem ([1 2 3; 1 2 3], 2, 0)
@result{} [](4x0)
@end group
@end example
@xseealso{@ref{XREFcat,,cat}, @ref{XREFkron,,kron}, @ref{XREFrepmat,,repmat}}
@end deftypefn
The functions @code{linspace} and @code{logspace} make it very easy to
create vectors with evenly or logarithmically spaced elements.
@xref{Ranges}.
@c linspace libinterp/corefcn/data.cc
@anchor{XREFlinspace}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{y} =} linspace (@var{start}, @var{end})
@deftypefnx {} {@var{y} =} linspace (@var{start}, @var{end}, @var{n})
Return a row vector with @var{n} linearly spaced elements between @var{start}
and @var{end}.
If the number of elements @var{n} is greater than one, then the endpoints
@var{start} and @var{end} are always included in the range. If @var{start} is
greater than @var{end}, the elements are stored in decreasing order. If the
number of points @var{n} is not specified, a value of 100 is used.
The @code{linspace} function returns a row vector when both @var{start} and
@var{end} are scalars. If one, or both, inputs are vectors, then
@code{linspace} transforms them to column vectors and returns a matrix where
each row is an independent sequence between
@w{@code{@var{start}(@var{row_n}), @var{end}(@var{row_n})}}.
Programming Notes: For compatibility with @sc{matlab}, return the second
argument (@var{end}) when a single value (@var{n} = 1) is requested. If
@var{n} is not an integer then @code{floor (@var{n})} is used to round the
number of elements. If @var{n} is zero or negative then an empty 1x0 matrix
is returned.
@xseealso{@ref{XREFcolon,,colon}, @ref{XREFlogspace,,logspace}}
@end deftypefn
@c logspace scripts/general/logspace.m
@anchor{XREFlogspace}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{y} =} logspace (@var{a}, @var{b})
@deftypefnx {} {@var{y} =} logspace (@var{a}, @var{b}, @var{n})
@deftypefnx {} {@var{y} =} logspace (@var{a}, pi)
@deftypefnx {} {@var{y} =} logspace (@var{a}, pi, @var{n})
Return a row vector with @var{n} elements logarithmically spaced from
@tex
$10^{a}$ to $10^{b}$.
@end tex
@ifnottex
10^@var{a} to 10^@var{b}.
@end ifnottex
If the number of elements @var{n} is unspecified it defaults to 50.
If @var{b} is equal to
@tex
$\pi$,
@end tex
@ifnottex
pi,
@end ifnottex
the points are between
@tex
$10^{a}$ and $\pi$,
@end tex
@ifnottex
10^@var{a} and pi,
@end ifnottex
@emph{not}
@tex
$10^{a}$ and $10^{\pi}$,
@end tex
@ifnottex
10^@var{a} and 10^pi,
@end ifnottex
which is useful in digital signal processing.
Programming Notes: For compatibility with @sc{matlab}, return the right-hand
side of the range
@tex
($10^{b}$)
@end tex
@ifnottex
(10^@var{b})
@end ifnottex
when a single value (@var{n} = 1) is requested.
If @var{n} is not an integer then @code{floor (@var{n})} is used to round
the number of elements. If @var{n} is zero or negative then an empty 1x0
matrix is returned.
@xseealso{@ref{XREFlinspace,,linspace}}
@end deftypefn
@c rand libinterp/corefcn/rand.cc
@anchor{XREFrand}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{x} =} rand (@var{n})
@deftypefnx {} {@var{x} =} rand (@var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{x} =} rand ([@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{x} =} rand (@dots{}, "single")
@deftypefnx {} {@var{x} =} rand (@dots{}, "double")
@deftypefnx {} {@var{v} =} rand ("state")
@deftypefnx {} {} rand ("state", @var{v})
@deftypefnx {} {} rand ("state", "reset")
@deftypefnx {} {@var{v} =} rand ("seed")
@deftypefnx {} {} rand ("seed", @var{v})
@deftypefnx {} {} rand ("seed", "reset")
Return a matrix with random elements uniformly distributed on the
interval (0, 1).
The arguments are handled the same as the arguments for @code{eye}.
You can query the state of the random number generator using the form
@example
v = rand ("state")
@end example
This returns a column vector @var{v} of length 625. Later, you can restore
the random number generator to the state @var{v} using the form
@example
rand ("state", v)
@end example
@noindent
You may also initialize the state vector from an arbitrary vector of length
@leq{} 625 for @var{v}. This new state will be a hash based on the value of
@var{v}, not @var{v} itself.
By default, the generator is initialized by contributing entropy from the
wall clock time, the CPU time, the current fraction of a second, the process
ID and---if available---up to 1024 bits from the C++ random numbers source
@code{random_device}, which might be non-deterministic (implementation
specific). Note that this differs from @sc{matlab}, which always initializes
the state to the same state at startup. To obtain behavior comparable to
@sc{matlab}, initialize with a deterministic state vector in Octave's startup
files (@pxref{Startup Files}).
To compute the pseudo-random sequence, @code{rand} uses the Mersenne
Twister with a period of @math{2^{19937}-1}
(See @nospell{M. Matsumoto and T. Nishimura},
@cite{Mersenne Twister: A 623-dimensionally equidistributed uniform
pseudorandom number generator},
@nospell{ACM} Trans.@: on Modeling and Computer Simulation Vol.@: 8, No.@: 1,
pp.@: 3--30, January 1998,
@url{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html}).
Do @strong{not} use for cryptography without securely hashing several
returned values together, otherwise the generator state can be learned after
reading 624 consecutive values.
Older versions of Octave used a different random number generator.
The new generator is used by default as it is significantly faster than the
old generator, and produces random numbers with a significantly longer cycle
time. However, in some circumstances it might be desirable to obtain the
same random sequences as produced by the old generators. To do this the
keyword @qcode{"seed"} is used to specify that the old generators should
be used, as in
@example
rand ("seed", val)
@end example
@noindent
which sets the seed of the generator to @var{val}. The seed of the
generator can be queried with
@example
s = rand ("seed")
@end example
However, it should be noted that querying the seed will not cause
@code{rand} to use the old generators, only setting the seed will. To cause
@code{rand} to once again use the new generators, the keyword
@qcode{"state"} should be used to reset the state of the @code{rand}.
The state or seed of the generator can be reset to a new random value using
the @qcode{"reset"} keyword.
The class of the value returned can be controlled by a trailing
@qcode{"double"} or @qcode{"single"} argument. These are the only valid
classes.
@xseealso{@ref{XREFrandn,,randn}, @ref{XREFrande,,rande}, @ref{XREFrandg,,randg}, @ref{XREFrandp,,randp}}
@end deftypefn
@c randi scripts/general/randi.m
@anchor{XREFrandi}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{R} =} randi (@var{imax})
@deftypefnx {} {@var{R} =} randi (@var{imax}, @var{n})
@deftypefnx {} {@var{R} =} randi (@var{imax}, @var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{R} =} randi ([@var{imin} @var{imax}], @dots{})
@deftypefnx {} {@var{R} =} randi (@dots{}, "@var{class}")
Return random integers in the range 1:@var{imax}.
Additional arguments determine the shape of the return matrix. When no
arguments are specified a single random integer is returned. If one
argument @var{n} is specified then a square matrix @w{(@var{n} x @var{n})}
is returned. Two or more arguments will return a multi-dimensional matrix
@w{(@var{m} x @var{n} x @dots{})}.
The integer range may optionally be described by a two-element matrix with a
lower and upper bound in which case the returned integers will be on the
interval @w{[@var{imin}, @var{imax}]}.
The optional argument @var{class} will return a matrix of the requested
type. The default is @qcode{"double"}.
The following example returns 150 integers in the range 1--10.
@example
ri = randi (10, 150, 1)
@end example
Implementation Note: @code{randi} relies internally on @code{rand} which
uses class @qcode{"double"} to represent numbers. This limits the maximum
integer (@var{imax}) and range (@var{imax} - @var{imin}) to the value
returned by the @code{flintmax} function. For IEEE@tie{}754 floating point
numbers this value is @w{@math{2^{53} - 1}}.
@xseealso{@ref{XREFrand,,rand}, @ref{XREFrandn,,randn}}
@end deftypefn
@c randn libinterp/corefcn/rand.cc
@anchor{XREFrandn}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{x} =} randn (@var{n})
@deftypefnx {} {@var{x} =} randn (@var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{x} =} randn ([@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{x} =} randn (@dots{}, "single")
@deftypefnx {} {@var{x} =} randn (@dots{}, "double")
@deftypefnx {} {@var{v} =} randn ("state")
@deftypefnx {} {} randn ("state", @var{v})
@deftypefnx {} {} randn ("state", "reset")
@deftypefnx {} {@var{v} =} randn ("seed")
@deftypefnx {} {} randn ("seed", @var{v})
@deftypefnx {} {} randn ("seed", "reset")
Return a matrix with normally distributed random elements having zero mean
and variance one.
The arguments are handled the same as the arguments for @code{rand}.
By default, @code{randn} uses the @nospell{Marsaglia and Tsang}
``Ziggurat technique'' to transform from a uniform to a normal distribution.
The class of the value returned can be controlled by a trailing
@qcode{"double"} or @qcode{"single"} argument. These are the only valid
classes.
Reference: @nospell{G. Marsaglia and W.W. Tsang},
@cite{Ziggurat Method for Generating Random Variables},
J. Statistical Software, vol 5, 2000,
@url{https://www.jstatsoft.org/v05/i08/}
@xseealso{@ref{XREFrand,,rand}, @ref{XREFrande,,rande}, @ref{XREFrandg,,randg}, @ref{XREFrandp,,randp}}
@end deftypefn
@c rande libinterp/corefcn/rand.cc
@anchor{XREFrande}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{x} =} rande (@var{n})
@deftypefnx {} {@var{x} =} rande (@var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{x} =} rande ([@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{x} =} rande (@dots{}, "single")
@deftypefnx {} {@var{x} =} rande (@dots{}, "double")
@deftypefnx {} {@var{v} =} rande ("state")
@deftypefnx {} {} rande ("state", @var{v})
@deftypefnx {} {} rande ("state", "reset")
@deftypefnx {} {@var{v} =} rande ("seed")
@deftypefnx {} {} rande ("seed", @var{v})
@deftypefnx {} {} rande ("seed", "reset")
Return a matrix with exponentially distributed random elements.
The arguments are handled the same as the arguments for @code{rand}.
By default, @code{rande} uses the @nospell{Marsaglia and Tsang}
``Ziggurat technique'' to transform from a uniform to an exponential
distribution.
The class of the value returned can be controlled by a trailing
@qcode{"double"} or @qcode{"single"} argument. These are the only valid
classes.
Reference: @nospell{G. Marsaglia and W.W. Tsang},
@cite{Ziggurat Method for Generating Random Variables},
J. Statistical Software, vol 5, 2000,
@url{https://www.jstatsoft.org/v05/i08/}
@xseealso{@ref{XREFrand,,rand}, @ref{XREFrandn,,randn}, @ref{XREFrandg,,randg}, @ref{XREFrandp,,randp}}
@end deftypefn
@c randp libinterp/corefcn/rand.cc
@anchor{XREFrandp}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{x} =} randp (@var{l}, @var{n})
@deftypefnx {} {@var{x} =} randp (@var{l}, @var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{x} =} randp (@var{l}, [@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{x} =} randp (@dots{}, "single")
@deftypefnx {} {@var{x} =} randp (@dots{}, "double")
@deftypefnx {} {@var{v} =} randp ("state")
@deftypefnx {} {} randp ("state", @var{v})
@deftypefnx {} {} randp ("state", "reset")
@deftypefnx {} {@var{v} =} randp ("seed")
@deftypefnx {} {} randp ("seed", @var{v})
@deftypefnx {} {} randp ("seed", "reset")
Return a matrix with Poisson distributed random elements with mean value
parameter given by the first argument, @var{l}.
The arguments are handled the same as the arguments for @code{rand}, except
for the argument @var{l}.
Five different algorithms are used depending on the range of @var{l} and
whether or not @var{l} is a scalar or a matrix.
@table @asis
@item For scalar @var{l} @leq{} 12, use direct method.
W.H. Press, et al., @cite{Numerical Recipes in C},
Cambridge University Press, 1992.
@item For scalar @var{l} > 12, use rejection method.[1]
W.H. Press, et al., @cite{Numerical Recipes in C},
Cambridge University Press, 1992.
@item For matrix @var{l} @leq{} 10, use inversion method.[2]
@nospell{E. Stadlober, et al., WinRand source code}, available via FTP.
@item For matrix @var{l} > 10, use patchwork rejection method.
@nospell{E. Stadlober, et al., WinRand source code}, available via FTP, or
@nospell{H. Zechner}, @cite{Efficient sampling from continuous and discrete
unimodal distributions}, Doctoral Dissertation, 156pp., Technical
University @nospell{Graz}, Austria, 1994.
@item For @var{l} > 1e8, use normal approximation.
@nospell{L. Montanet}, et al., @cite{Review of Particle Properties},
Physical Review D 50 p1284, 1994.
@end table
The class of the value returned can be controlled by a trailing
@qcode{"double"} or @qcode{"single"} argument. These are the only valid
classes.
@xseealso{@ref{XREFrand,,rand}, @ref{XREFrandn,,randn}, @ref{XREFrande,,rande}, @ref{XREFrandg,,randg}}
@end deftypefn
@c randg libinterp/corefcn/rand.cc
@anchor{XREFrandg}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{x} =} randg (@var{a}, @var{n})
@deftypefnx {} {@var{x} =} randg (@var{a}, @var{m}, @var{n}, @dots{})
@deftypefnx {} {@var{x} =} randg (@var{a}, [@var{m} @var{n} @dots{}])
@deftypefnx {} {@var{x} =} randg (@dots{}, "single")
@deftypefnx {} {@var{x} =} randg (@dots{}, "double")
@deftypefnx {} {@var{v} =} randg ("state")
@deftypefnx {} {} randg ("state", @var{v})
@deftypefnx {} {} randg ("state", "reset")
@deftypefnx {} {@var{v} =} randg ("seed")
@deftypefnx {} {} randg ("seed", @var{v})
@deftypefnx {} {} randg ("seed", "reset")
Return a matrix with @code{gamma (@var{a},1)} distributed random elements.
The arguments are handled the same as the arguments for @code{rand}, except
for the argument @var{a}.
This can be used to generate many distributions:
@table @asis
@item @code{gamma (a, b)} for @code{a > -1}, @code{b > 0}
@example
r = b * randg (a)
@end example
@item @code{beta (a, b)} for @code{a > -1}, @code{b > -1}
@example
@group
r1 = randg (a, 1)
r = r1 / (r1 + randg (b, 1))
@end group
@end example
@item @code{Erlang (a, n)}
@example
r = a * randg (n)
@end example
@item @code{chisq (df)} for @code{df > 0}
@example
r = 2 * randg (df / 2)
@end example
@item @code{t (df)} for @code{0 < df < inf} (use randn if df is infinite)
@example
r = randn () / sqrt (2 * randg (df / 2) / df)
@end example
@item @code{F (n1, n2)} for @code{0 < n1}, @code{0 < n2}
@example
@group
## r1 equals 1 if n1 is infinite
r1 = 2 * randg (n1 / 2) / n1
## r2 equals 1 if n2 is infinite
r2 = 2 * randg (n2 / 2) / n2
r = r1 / r2
@end group
@end example
@item negative @code{binomial (n, p)} for @code{n > 0}, @code{0 < p <= 1}
@example
r = randp ((1 - p) / p * randg (n))
@end example
@item non-central @code{chisq (df, L)}, for @code{df >= 0} and @code{L > 0}
(use chisq if @code{L = 0})
@example
@group
r = randp (L / 2)
r(r > 0) = 2 * randg (r(r > 0))
r(df > 0) += 2 * randg (df(df > 0)/2)
@end group
@end example
@item @code{Dirichlet (a1, @dots{} ak)}
@example
@group
r = (randg (a1), @dots{}, randg (ak))
r = r / sum (r)
@end group
@end example
@end table
The class of the value returned can be controlled by a trailing
@qcode{"double"} or @qcode{"single"} argument. These are the only valid
classes.
@xseealso{@ref{XREFrand,,rand}, @ref{XREFrandn,,randn}, @ref{XREFrande,,rande}, @ref{XREFrandp,,randp}}
@end deftypefn
@c rng scripts/general/rng.m
@anchor{XREFrng}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {} rng (@var{seed})
@deftypefnx {} {} rng (@var{seed}, "@var{generator}")
@deftypefnx {} {} rng ("shuffle")
@deftypefnx {} {} rng ("shuffle", "@var{generator}")
@deftypefnx {} {} rng ("default")
@deftypefnx {} {@var{s} =} rng ()
@deftypefnx {} {} rng (@var{s})
@deftypefnx {} {@var{s} =} rng (@dots{})
Set or query the seed of the random number generator used by @code{rand} and
@code{randn}.
The input @var{seed} is a scalar numeric value used to initialize the state
vector of the random number generator.
The optional string @var{generator} specifies the type of random number
generator to be used. Its value can be @qcode{"twister"},
@qcode{"v5uniform"}, or @qcode{"v5normal"}. The @qcode{"twister"} keyword
is described below. @qcode{"v5uniform"} and @qcode{"v5normal"} refer to
older versions of Octave that used to use a different random number
generator.
The state or seed of the random number generator can be reset to a new
random value using the @qcode{"shuffle"} keyword.
The random number generator can be reset to default values using the
@qcode{"default"} keyword. The default values are to use the Mersenne
Twister generator with a seed of 0.
The optional return value @var{s} contains the state of the random number
generator at the time the function is called (i.e., before it might be
modified according to the input arguments). It is encoded as a structure
variable with three fields: @qcode{"Type"}, @qcode{"Seed"}, and
@qcode{"State"}. The random number generator can be restored to the state
@var{s} using @code{rng (@var{s})}. This is useful when the identical
sequence of pseudo-random numbers is required for an algorithm.
By default, and with the @qcode{"twister"} option, pseudo-random sequences
are computed using the Mersenne Twister with a period of @math{2^{19937}-1}
(See @nospell{M. Matsumoto and T. Nishimura},
@cite{Mersenne Twister: A 623-dimensionally equidistributed uniform
pseudorandom number generator},
@nospell{ACM} Trans.@: on Modeling and Computer Simulation Vol.@: 8, No.@: 1,
pp.@: 3--30, January 1998,
@url{http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html}).
Do @strong{not} use for cryptography without securely hashing several
returned values together, otherwise the generator state can be learned after
reading 624 consecutive values.
@xseealso{@ref{XREFrand,,rand}, @ref{XREFrandn,,randn}}
@end deftypefn
The generators operate in the new or old style together, it is not
possible to mix the two. Initializing any generator with
@qcode{"state"} or @qcode{"seed"} causes the others to switch to the
same style for future calls.
The state of each generator is independent and calls to different
generators can be interleaved without affecting the final result. For
example,
@example
@group
rand ("state", [11, 22, 33]);
randn ("state", [44, 55, 66]);
u = rand (100, 1);
n = randn (100, 1);
@end group
@end example
@noindent
and
@example
@group
rand ("state", [11, 22, 33]);
randn ("state", [44, 55, 66]);
u = zeros (100, 1);
n = zeros (100, 1);
for i = 1:100
u(i) = rand ();
n(i) = randn ();
end
@end group
@end example
@noindent
produce equivalent results. When the generators are initialized in
the old style with @qcode{"seed"} only @code{rand} and @code{randn} are
independent, because the old @code{rande}, @code{randg} and
@code{randp} generators make calls to @code{rand} and @code{randn}.
The generators are initialized with random states at start-up, so
that the sequences of random numbers are not the same each time you run
Octave.@footnote{The old versions of @code{rand} and @code{randn}
obtain their initial seeds from the system clock.} If you really do
need to reproduce a sequence of numbers exactly, you can set the state
or seed to a specific value.
If invoked without arguments, @code{rand} and @code{randn} return a
single element of a random sequence.
The original @code{rand} and @code{randn} functions use Fortran code from
@sc{ranlib}, a library of Fortran routines for random number generation,
compiled by Barry W. Brown and @nospell{James Lovato} of the Department of
Biomathematics at The University of Texas, M.D. Anderson Cancer Center,
Houston, TX 77030.
@c randperm libinterp/corefcn/rand.cc
@anchor{XREFrandperm}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{v} =} randperm (@var{n})
@deftypefnx {} {@var{v} =} randperm (@var{n}, @var{m})
Return a row vector containing a random permutation of @code{1:@var{n}}.
If @var{m} is supplied, return @var{m} unique entries, sampled without
replacement from @code{1:@var{n}}.
The complexity is O(@var{n}) in memory and O(@var{m}) in time, unless
@var{m} < @var{n}/5, in which case O(@var{m}) memory is used as well. The
randomization is performed using rand(). All permutations are equally
likely.
@xseealso{@ref{XREFperms,,perms}}
@end deftypefn
@node Famous Matrices
@section Famous Matrices
The following functions return famous matrix forms.
@c gallery scripts/special-matrix/gallery.m
@anchor{XREFgallery}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {} gallery (@var{name})
@deftypefnx {} {} gallery (@var{name}, @var{args})
Create interesting matrices for testing.
@end deftypefn
@deftypefn {} {@var{c} =} gallery ("cauchy", @var{x})
@deftypefnx {} {@var{c} =} gallery ("cauchy", @var{x}, @var{y})
Create a Cauchy matrix.
@end deftypefn
@deftypefn {} {@var{c} =} gallery ("chebspec", @var{n})
@deftypefnx {} {@var{c} =} gallery ("chebspec", @var{n}, @var{k})
Create a Chebyshev spectral differentiation matrix.
@end deftypefn
@deftypefn {} {@var{c} =} gallery ("chebvand", @var{p})
@deftypefnx {} {@var{c} =} gallery ("chebvand", @var{m}, @var{p})
Create a @nospell{Vandermonde}-like matrix for the Chebyshev polynomials.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("chow", @var{n})
@deftypefnx {} {@var{a} =} gallery ("chow", @var{n}, @var{alpha})
@deftypefnx {} {@var{a} =} gallery ("chow", @var{n}, @var{alpha}, @var{delta})
Create a Chow matrix -- a singular Toeplitz lower Hessenberg matrix.
@end deftypefn
@deftypefn {} {@var{c} =} gallery ("circul", @var{v})
Create a circulant matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("clement", @var{n})
@deftypefnx {} {@var{a} =} gallery ("clement", @var{n}, @var{k})
Create a tridiagonal matrix with zero diagonal entries.
@end deftypefn
@deftypefn {} {@var{c} =} gallery ("compar", @var{a})
@deftypefnx {} {@var{c} =} gallery ("compar", @var{a}, @var{k})
Create a comparison matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("condex", @var{n})
@deftypefnx {} {@var{a} =} gallery ("condex", @var{n}, @var{k})
@deftypefnx {} {@var{a} =} gallery ("condex", @var{n}, @var{k}, @var{theta})
Create a @nospell{"counterexample"} matrix to a condition estimator.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("cycol", [@var{m} @var{n}])
@deftypefnx {} {@var{a} =} gallery ("cycol", @var{n})
@deftypefnx {} {@var{a} =} gallery (@dots{}, @var{k})
Create a matrix whose columns repeat cyclically.
@end deftypefn
@deftypefn {} {[@var{c}, @var{d}, @var{e}] =} gallery ("dorr", @var{n})
@deftypefnx {} {[@var{c}, @var{d}, @var{e}] =} gallery ("dorr", @var{n}, @var{theta})
@deftypefnx {} {@var{a} =} gallery ("dorr", @dots{})
Create a diagonally dominant, ill-conditioned, tridiagonal matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("dramadah", @var{n})
@deftypefnx {} {@var{a} =} gallery ("dramadah", @var{n}, @var{k})
Create a (0, 1) matrix whose inverse has large integer entries.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("fiedler", @var{c})
Create a symmetric @nospell{Fiedler} matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("forsythe", @var{n})
@deftypefnx {} {@var{a} =} gallery ("forsythe", @var{n}, @var{alpha})
@deftypefnx {} {@var{a} =} gallery ("forsythe", @var{n}, @var{alpha}, @var{lambda})
Create a @nospell{Forsythe} matrix (a perturbed Jordan block).
@end deftypefn
@deftypefn {} {@var{f} =} gallery ("frank", @var{n})
@deftypefnx {} {@var{f} =} gallery ("frank", @var{n}, @var{k})
Create a Frank matrix (ill-conditioned eigenvalues).
@end deftypefn
@deftypefn {} {@var{c} =} gallery ("gcdmat", @var{n})
Create a greatest common divisor matrix.
@var{c} is an @var{n}-by-@var{n} matrix whose values correspond to the
greatest common divisor of its coordinate values, i.e., @var{c}(i,j)
correspond @code{gcd (i, j)}.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("gearmat", @var{n})
@deftypefnx {} {@var{a} =} gallery ("gearmat", @var{n}, @var{i})
@deftypefnx {} {@var{a} =} gallery ("gearmat", @var{n}, @var{i}, @var{j})
Create a Gear matrix.
@end deftypefn
@deftypefn {} {@var{g} =} gallery ("grcar", @var{n})
@deftypefnx {} {@var{g} =} gallery ("grcar", @var{n}, @var{k})
Create a Toeplitz matrix with sensitive eigenvalues.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("hanowa", @var{n})
@deftypefnx {} {@var{a} =} gallery ("hanowa", @var{n}, @var{d})
Create a matrix whose eigenvalues lie on a vertical line in the complex
plane.
@end deftypefn
@deftypefn {} {@var{v} =} gallery ("house", @var{x})
@deftypefnx {} {[@var{v}, @var{beta}] =} gallery ("house", @var{x})
Create a householder matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("integerdata", @var{imax}, [@var{M} @var{N} @dots{}], @var{j})
@deftypefnx {} {@var{a} =} gallery ("integerdata", @var{imax}, @var{M}, @var{N}, @dots{}, @var{j})
@deftypefnx {} {@var{a} =} gallery ("integerdata", [@var{imin}, @var{imax}], [@var{M} @var{N} @dots{}], @var{j})
@deftypefnx {} {@var{a} =} gallery ("integerdata", [@var{imin}, @var{imax}], @var{M}, @var{N}, @dots{}, @var{j})
@deftypefnx {} {@var{a} =} gallery ("integerdata", @dots{}, "@var{class}")
Create a matrix with random integers in the range [1, @var{imax}].
If @var{imin} is given then the integers are in the range
[@var{imin}, @var{imax}].
The second input is a matrix of dimensions describing the size of the
output. The dimensions can also be input as comma-separated arguments.
The input @var{j} is an integer index in the range [0, 2^32-1]. The values
of the output matrix are always exactly the same (reproducibility) for a
given size input and @var{j} index.
The final optional argument determines the class of the resulting matrix.
Possible values for @var{class}: @qcode{"uint8"}, @qcode{"uint16"},
@qcode{"uint32"}, @qcode{"int8"}, @qcode{"int16"}, int32", @qcode{"single"},
@qcode{"double"}. The default is @qcode{"double"}.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("invhess", @var{x})
@deftypefnx {} {@var{a} =} gallery ("invhess", @var{x}, @var{y})
Create the inverse of an upper Hessenberg matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("invol", @var{n})
Create an involutory matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("ipjfact", @var{n})
@deftypefnx {} {@var{a} =} gallery ("ipjfact", @var{n}, @var{k})
Create a Hankel matrix with factorial elements.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("jordbloc", @var{n})
@deftypefnx {} {@var{a} =} gallery ("jordbloc", @var{n}, @var{lambda})
Create a Jordan block.
@end deftypefn
@deftypefn {} {@var{u} =} gallery ("kahan", @var{n})
@deftypefnx {} {@var{u} =} gallery ("kahan", @var{n}, @var{theta})
@deftypefnx {} {@var{u} =} gallery ("kahan", @var{n}, @var{theta}, @var{pert})
Create a @nospell{Kahan} matrix (upper trapezoidal).
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("kms", @var{n})
@deftypefnx {} {@var{a} =} gallery ("kms", @var{n}, @var{rho})
Create a @nospell{Kac-Murdock-Szego} Toeplitz matrix.
@end deftypefn
@deftypefn {} {@var{b} =} gallery ("krylov", @var{a})
@deftypefnx {} {@var{b} =} gallery ("krylov", @var{a}, @var{x})
@deftypefnx {} {@var{b} =} gallery ("krylov", @var{a}, @var{x}, @var{j})
Create a Krylov matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("lauchli", @var{n})
@deftypefnx {} {@var{a} =} gallery ("lauchli", @var{n}, @var{mu})
Create a @nospell{Lauchli} matrix (rectangular).
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("lehmer", @var{n})
Create a @nospell{Lehmer} matrix (symmetric positive definite).
@end deftypefn
@deftypefn {} {@var{t} =} gallery ("lesp", @var{n})
Create a tridiagonal matrix with real, sensitive eigenvalues.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("lotkin", @var{n})
Create a @nospell{Lotkin} matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("minij", @var{n})
Create a symmetric positive definite matrix MIN(i,j).
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("moler", @var{n})
@deftypefnx {} {@var{a} =} gallery ("moler", @var{n}, @var{alpha})
Create a @nospell{Moler} matrix (symmetric positive definite).
@end deftypefn
@deftypefn {} {[@var{a}, @var{t}] =} gallery ("neumann", @var{n})
Create a singular matrix from the discrete @nospell{Neumann} problem
(sparse).
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("normaldata", [@var{M} @var{N} @dots{}], @var{j})
@deftypefnx {} {@var{a} =} gallery ("normaldata", @var{M}, @var{N}, @dots{}, @var{j})
@deftypefnx {} {@var{a} =} gallery ("normaldata", @dots{}, "@var{class}")
Create a matrix with random samples from the standard normal distribution
(mean = 0, std = 1).
The first input is a matrix of dimensions describing the size of the output.
The dimensions can also be input as comma-separated arguments.
The input @var{j} is an integer index in the range [0, 2^32-1]. The values
of the output matrix are always exactly the same (reproducibility) for a
given size input and @var{j} index.
The final optional argument determines the class of the resulting matrix.
Possible values for @var{class}: @qcode{"single"}, @qcode{"double"}.
The default is @qcode{"double"}.
@end deftypefn
@deftypefn {} {@var{q} =} gallery ("orthog", @var{n})
@deftypefnx {} {@var{q} =} gallery ("orthog", @var{n}, @var{k})
Create orthogonal and nearly orthogonal matrices.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("parter", @var{n})
Create a @nospell{Parter} matrix (a Toeplitz matrix with singular values
near pi).
@end deftypefn
@deftypefn {} {@var{p} =} gallery ("pei", @var{n})
@deftypefnx {} {@var{p} =} gallery ("pei", @var{n}, @var{alpha})
Create a Pei matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("poisson", @var{n})
Create a block tridiagonal matrix from Poisson's equation (sparse).
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("prolate", @var{n})
@deftypefnx {} {@var{a} =} gallery ("prolate", @var{n}, @var{w})
Create a prolate matrix (symmetric, ill-conditioned Toeplitz matrix).
@end deftypefn
@deftypefn {} {@var{h} =} gallery ("randhess", @var{x})
Create a random, orthogonal upper Hessenberg matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("rando", @var{n})
@deftypefnx {} {@var{a} =} gallery ("rando", @var{n}, @var{k})
Create a random matrix with elements -1, 0 or 1.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("randsvd", @var{n})
@deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa})
@deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}, @var{mode})
@deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}, @var{mode}, @var{kl})
@deftypefnx {} {@var{a} =} gallery ("randsvd", @var{n}, @var{kappa}, @var{mode}, @var{kl}, @var{ku})
Create a random matrix with pre-assigned singular values.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("redheff", @var{n})
Create a zero and ones matrix of @nospell{Redheffer} associated with the
Riemann hypothesis.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("riemann", @var{n})
Create a matrix associated with the Riemann hypothesis.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("ris", @var{n})
Create a symmetric Hankel matrix.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("smoke", @var{n})
@deftypefnx {} {@var{a} =} gallery ("smoke", @var{n}, @var{k})
Create a complex matrix, with a @nospell{"smoke ring"} pseudospectrum.
@end deftypefn
@deftypefn {} {@var{t} =} gallery ("toeppd", @var{n})
@deftypefnx {} {@var{t} =} gallery ("toeppd", @var{n}, @var{m})
@deftypefnx {} {@var{t} =} gallery ("toeppd", @var{n}, @var{m}, @var{w})
@deftypefnx {} {@var{t} =} gallery ("toeppd", @var{n}, @var{m}, @var{w}, @var{theta})
Create a symmetric positive definite Toeplitz matrix.
@end deftypefn
@deftypefn {} {@var{p} =} gallery ("toeppen", @var{n})
@deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a})
@deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b})
@deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}, @var{c})
@deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}, @var{c}, @var{d})
@deftypefnx {} {@var{p} =} gallery ("toeppen", @var{n}, @var{a}, @var{b}, @var{c}, @var{d}, @var{e})
Create a pentadiagonal Toeplitz matrix (sparse).
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("tridiag", @var{x}, @var{y}, @var{z})
@deftypefnx {} {@var{a} =} gallery ("tridiag", @var{n})
@deftypefnx {} {@var{a} =} gallery ("tridiag", @var{n}, @var{c}, @var{d}, @var{e})
Create a tridiagonal matrix (sparse).
@end deftypefn
@deftypefn {} {@var{t} =} gallery ("triw", @var{n})
@deftypefnx {} {@var{t} =} gallery ("triw", @var{n}, @var{alpha})
@deftypefnx {} {@var{t} =} gallery ("triw", @var{n}, @var{alpha}, @var{k})
Create an upper triangular matrix discussed by
@nospell{Kahan, Golub, and Wilkinson}.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("uniformdata", [@var{M} @var{N} @dots{}], @var{j})
@deftypefnx {} {@var{a} =} gallery ("uniformdata", @var{M}, @var{N}, @dots{}, @var{j})
@deftypefnx {} {@var{a} =} gallery ("uniformdata", @dots{}, "@var{class}")
Create a matrix with random samples from the standard uniform distribution
(range [0,1]).
The first input is a matrix of dimensions describing the size of the output.
The dimensions can also be input as comma-separated arguments.
The input @var{j} is an integer index in the range [0, 2^32-1]. The values
of the output matrix are always exactly the same (reproducibility) for a
given size input and @var{j} index.
The final optional argument determines the class of the resulting matrix.
Possible values for @var{class}: @qcode{"single"}, @qcode{"double"}.
The default is @qcode{"double"}.
@end deftypefn
@deftypefn {} {@var{a} =} gallery ("wathen", @var{nx}, @var{ny})
@deftypefnx {} {@var{a} =} gallery ("wathen", @var{nx}, @var{ny}, @var{k})
Create the @nospell{Wathen} matrix.
@end deftypefn
@deftypefn {} {[@var{a}, @var{b}] =} gallery ("wilk", @var{n})
Create various specific matrices devised/discussed by Wilkinson.
@end deftypefn
@c hadamard scripts/special-matrix/hadamard.m
@anchor{XREFhadamard}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{h} =} hadamard (@var{n})
Construct a Hadamard matrix (@nospell{Hn}) of size @var{n}-by-@var{n}.
The size @var{n} must be of the form @math{2^k * p} in which p is one of
1, 12, 20 or 28. The returned matrix is normalized, meaning
@w{@code{Hn(:,1) == 1}}@ and @w{@code{Hn(1,:) == 1}}.
Some of the properties of Hadamard matrices are:
@itemize @bullet
@item
@code{kron (Hm, Hn)} is a Hadamard matrix of size @var{m}-by-@var{n}.
@item
@code{Hn * Hn' = @var{n} * eye (@var{n})}.
@item
The rows of @nospell{Hn} are orthogonal.
@item
@code{det (@var{A}) <= abs (det (Hn))} for all @var{A} with
@w{@code{abs (@var{A}(i, j)) <= 1}}.
@item
Multiplying any row or column by -1 and the matrix will remain a Hadamard
matrix.
@end itemize
@xseealso{@ref{XREFcompan,,compan}, @ref{XREFhankel,,hankel}, @ref{XREFtoeplitz,,toeplitz}}
@end deftypefn
@c hankel scripts/special-matrix/hankel.m
@anchor{XREFhankel}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{h} =} hankel (@var{c})
@deftypefnx {} {@var{h} =} hankel (@var{c}, @var{r})
Return the Hankel matrix constructed from the first column @var{c}, and
(optionally) the last row @var{r}.
If the last element of @var{c} is not the same as the first element of
@var{r}, the last element of @var{c} is used. If the second argument is
omitted, it is assumed to be a vector of zeros with the same size as
@var{c}.
A Hankel matrix formed from an m-vector @var{c}, and an n-vector @var{r},
has the elements
@tex
$$
H(i, j) = \cases{c_{i+j-1},&$i+j-1\le m$;\cr r_{i+j-m},&otherwise.\cr}
$$
@end tex
@ifnottex
@example
@group
H(i,j) = c(i+j-1), i+j-1 <= m;
H(i,j) = r(i+j-m), otherwise
@end group
@end example
@end ifnottex
@xseealso{@ref{XREFhadamard,,hadamard}, @ref{XREFtoeplitz,,toeplitz}}
@end deftypefn
@c hilb scripts/special-matrix/hilb.m
@anchor{XREFhilb}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{h} =} hilb (@var{n})
Return the Hilbert matrix of order @var{n}.
The @math{i,j} element of a Hilbert matrix is defined as
@tex
$$
H(i, j) = {1 \over (i + j - 1)}
$$
@end tex
@ifnottex
@example
H(i, j) = 1 / (i + j - 1)
@end example
@end ifnottex
Hilbert matrices are close to being singular which make them difficult to
invert with numerical routines. Comparing the condition number of a random
matrix 5x5 matrix with that of a Hilbert matrix of order 5 reveals just how
difficult the problem is.
@example
@group
cond (rand (5))
@result{} 14.392
cond (hilb (5))
@result{} 4.7661e+05
@end group
@end example
@xseealso{@ref{XREFinvhilb,,invhilb}}
@end deftypefn
@c invhilb scripts/special-matrix/invhilb.m
@anchor{XREFinvhilb}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{hinv} =} invhilb (@var{n})
Return the inverse of the Hilbert matrix of order @var{n}.
This can be computed exactly using
@tex
$$\eqalign{
A_{ij} &= -1^{i+j} (i+j-1)
\left( \matrix{n+i-1 \cr n-j } \right)
\left( \matrix{n+j-1 \cr n-i } \right)
\left( \matrix{i+j-2 \cr i-2 } \right)^2 \cr
&= { p(i)p(j) \over (i+j-1) }
}$$
where
$$
p(k) = -1^k \left( \matrix{ k+n-1 \cr k-1 } \right)
\left( \matrix{ n \cr k } \right)
$$
@end tex
@ifnottex
@example
@group
(i+j) /n+i-1\ /n+j-1\ /i+j-2\ 2
A(i,j) = -1 (i+j-1)( )( ) ( )
\ n-j / \ n-i / \ i-2 /
= p(i) p(j) / (i+j-1)
@end group
@end example
@noindent
where
@example
@group
k /k+n-1\ /n\
p(k) = -1 ( ) ( )
\ k-1 / \k/
@end group
@end example
@end ifnottex
The validity of this formula can easily be checked by expanding the binomial
coefficients in both formulas as factorials. It can be derived more
directly via the theory of Cauchy matrices. See @nospell{J. W. Demmel},
@cite{Applied Numerical Linear Algebra}, p.@: 92.
Compare this with the numerical calculation of @code{inv (hilb (n))},
which suffers from the ill-conditioning of the Hilbert matrix, and the
finite precision of your computer's floating point arithmetic.
@xseealso{@ref{XREFhilb,,hilb}}
@end deftypefn
@c magic scripts/special-matrix/magic.m
@anchor{XREFmagic}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{M} =} magic (@var{n})
Create an @var{n}-by-@var{n} magic square.
A magic square is an arrangement of the integers @code{1:n^2} such that the
row sums, column sums, and diagonal sums are all equal to the same value.
Note: @var{n} must be a scalar greater than or equal to 3. If you supply
@var{n} less than 3, magic returns either a nonmagic square, or else the
degenerate magic squares 1 and [].
@end deftypefn
@c pascal scripts/special-matrix/pascal.m
@anchor{XREFpascal}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{P} =} pascal (@var{n})
@deftypefnx {} {@var{P} =} pascal (@var{n}, @var{t})
Return the Pascal matrix of order @var{n} if @code{@var{t} = 0}.
The default value of @var{t} is 0.
When @code{@var{t} = 1}, return the pseudo-lower triangular
Cholesky@tie{}factor of the Pascal matrix (The sign of some columns may be
negative). This matrix is its own inverse, that is
@code{pascal (@var{n}, 1) ^ 2 == eye (@var{n})}.
If @code{@var{t} = -1}, return the true Cholesky@tie{}factor with strictly
positive values on the diagonal.
If @code{@var{t} = 2}, return a transposed and permuted version of
@code{pascal (@var{n}, 1)}, which is the cube root of the identity matrix.
That is, @code{pascal (@var{n}, 2) ^ 3 == eye (@var{n})}.
@xseealso{@ref{XREFchol,,chol}}
@end deftypefn
@c rosser scripts/special-matrix/rosser.m
@anchor{XREFrosser}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{R} =} rosser ()
Return the @nospell{Rosser} matrix.
This is a difficult test case used to evaluate eigenvalue algorithms.
@xseealso{@ref{XREFwilkinson,,wilkinson}, @ref{XREFeig,,eig}}
@end deftypefn
@c toeplitz scripts/special-matrix/toeplitz.m
@anchor{XREFtoeplitz}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{T} =} toeplitz (@var{c})
@deftypefnx {} {@var{T} =} toeplitz (@var{c}, @var{r})
Return the Toeplitz matrix constructed from the first column @var{c},
and optionally the first row @var{r}.
If the second argument is omitted, the first row is taken to be the
same as the first column. If the first element of @var{r} is not the same
as the first element of @var{c}, the first element of @var{c} is used.
A Toeplitz, or diagonal-constant, matrix has the same value along each
diagonal. Although it need not be square, it often is. An @nospell{MxN}
Toeplitz matrix has the form:
@tex
$$
\left[\matrix{c_1 & r_2 & r_3 & \cdots & r_n\cr
c_2 & c_1 & r_2 & \cdots & r_{n-1}\cr
c_3 & c_2 & c_1 & \cdots & r_{n-2}\cr
\vdots & \vdots & \vdots & \ddots & \vdots\cr
c_m & c_{m-1} & c_{m-2} & \ldots & c{m-n+1}}\right]
$$
@end tex
@ifnottex
@example
@group
c(1) r(2) r(3) @dots{} r(n)
c(2) c(1) r(2) @dots{} r(n-1)
c(3) c(2) c(1) @dots{} r(n-2)
. . . . .
. . . . .
. . . . .
c(m) c(m-1) c(m-2) @dots{} c(m-n+1)
@end group
@end example
@end ifnottex
@xseealso{@ref{XREFhankel,,hankel}}
@end deftypefn
@c vander scripts/special-matrix/vander.m
@anchor{XREFvander}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{V} =} vander (@var{c})
@deftypefnx {} {@var{V} =} vander (@var{c}, @var{n})
Return the @nospell{Vandermonde} matrix whose next to last column is
@var{c}.
If @var{n} is specified, it determines the number of columns; otherwise,
@var{n} is taken to be equal to the length of @var{c}.
A @nospell{Vandermonde} matrix has the form:
@tex
$$
\left[\matrix{c_1^{n-1} & \cdots & c_1^2 & c_1 & 1 \cr
c_2^{n-1} & \cdots & c_2^2 & c_2 & 1 \cr
\vdots & \ddots & \vdots & \vdots & \vdots \cr
c_n^{n-1} & \cdots & c_n^2 & c_n & 1 }\right]
$$
@end tex
@ifnottex
@example
@group
c(1)^(n-1) @dots{} c(1)^2 c(1) 1
c(2)^(n-1) @dots{} c(2)^2 c(2) 1
. . . . .
. . . . .
. . . . .
c(n)^(n-1) @dots{} c(n)^2 c(n) 1
@end group
@end example
@end ifnottex
@xseealso{@ref{XREFpolyfit,,polyfit}}
@end deftypefn
@c wilkinson scripts/special-matrix/wilkinson.m
@anchor{XREFwilkinson}
@html
<span style="display:block; margin-top:-4.5ex;"> </span>
@end html
@deftypefn {} {@var{W} =} wilkinson (@var{n})
Return the Wilkinson matrix of order @var{n}.
Wilkinson matrices are symmetric and tridiagonal with pairs of nearly, but
not exactly, equal eigenvalues. They are useful in testing the behavior and
performance of eigenvalue solvers.
@xseealso{@ref{XREFrosser,,rosser}, @ref{XREFeig,,eig}}
@end deftypefn
|