< M A T L A B > Copyright 1984-2001 The MathWorks, Inc. Version 6.1.0.450 Release 12.1 May 18 2001 To get started, select "MATLAB Help" from the Help menu. >> A = [ 1 2 3; 4, 5, 6; 7 8 9] A = 1 2 3 4 5 6 7 8 9 >> rand('state',sum(100*clock)); >>% The following indicates how you can get help about a matlab command >> help rand RAND Uniformly distributed random numbers. RAND(N) is an N-by-N matrix with random entries, chosen from a uniform distribution on the interval (0.0,1.0). RAND(M,N) and RAND([M,N]) are M-by-N matrices with random entries. RAND(M,N,P,...) or RAND([M,N,P,...]) generate random arrays. RAND with no arguments is a scalar whose value changes each time it is referenced. RAND(SIZE(A)) is the same size as A. RAND produces pseudo-random numbers. The sequence of numbers generated is determined by the state of the generator. Since MATLAB resets the state at start-up, the sequence of numbers generated will be the same unless the state is changed. S = RAND('state') is a 35-element vector containing the current state of the uniform generator. RAND('state',S) resets the state to S. RAND('state',0) resets the generator to its initial state. RAND('state',J), for integer J, resets the generator to its J-th state. RAND('state',sum(100*clock)) resets it to a different state each time. This generator can generate all the floating point numbers in the closed interval [2^(-53), 1-2^(-53)]. Theoretically, it can generate over 2^1492 values before repeating itself. MATLAB Version 4.x used random number generators with a single seed. RAND('seed',0) and RAND('seed',J) cause the MATLAB 4 generator to be used. RAND('seed') returns the current seed of the MATLAB 4 uniform generator. RAND('state',J) and RAND('state',S) cause the MATLAB 5 generator to be used. See also RANDN, SPRAND, SPRANDN, RANDPERM. >> A=rand(5,7) A = 0.7805 0.5975 0.1179 0.4667 0.1596 0.2782 0.2809 0.0536 0.3180 0.5104 0.6314 0.1433 0.7567 0.8026 0.3961 0.5157 0.8970 0.7216 0.9992 0.7273 0.4549 0.0500 0.3967 0.6851 0.3857 0.4146 0.8841 0.7248 0.2494 0.8504 0.9762 0.0044 0.8246 0.2576 0.7980 >> A = randint(3,4,[2,13]) A = 3 4 8 5 11 2 13 6 7 6 8 10 >> rref(A) ans = 1.0000 0 0 0.6033 0 1.0000 0 1.2934 0 0 1.0000 -0.2479 >> c = A\[1;2;3] c = 0.1565 0 -0.1054 0.2748 >> A = rand(7,9); >> % Let's look at a couple ways to solve Ax=b. First generate a random b. >> b = rand(7,1); >> % Now find a solution using A\b >> x = A\b x = 1.1733 1.5278 0 0.8572 0.0675 1.4295 0 -0.5993 -2.9703 >> % The above is only one solution, but we know that in fact there are >> % either no solutions or else infinitely many solutions, >> % since A has more columns than rows. >> % To find all solutions look at the reduced echelon form of the >> % augmented matrix [A b] >> rref([A b]) ans = Columns 1 through 7 1.0000 0 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 1.0000 Columns 8 through 10 -0.4677 0.4921 -0.0080 -0.1038 0.3787 0.4652 -0.1486 0.4164 -1.1477 0.2589 0.1875 0.1450 0.7875 -0.2185 0.2447 -0.2762 0.4190 0.3504 1.0634 -0.6322 1.2406 >> % From the above we see that the general solution is: >> % x1 = -.0080 +.4677 x8 -.4921 x9 >> % x2 = .4652 +.1038 x8 -.3787 x9 >> % etc. >> A = rand(3,4)+i*rand(3,4) A = 0.4789 + 0.3262i 0.5689 + 0.9115i 0.2730 + 0.9936i 0.0146 + 0.0233i 0.5369 + 0.3665i 0.2696 + 0.4378i 0.4520 + 0.7474i 0.1365 + 0.3093i 0.2412 + 0.7798i 0.3962 + 0.8037i 0.4589 + 0.6985i 0.0245 + 0.6058i