%%%% Try these commands.
t=1:3:11 % row vector
t =
1 4 7 10
A=randn(3)
A =
0.5377 0.8622 -0.4336
1.8339 0.3188 0.3426
-2.2588 -1.3077 3.5784
d=diag(A)
d =
0.5377
0.3188
3.5784
D=diag(d)
D =
0.5377 0 0
0 0.3188 0
0 0 3.5784
c = [1 2 3 4 5];
r = [1.5 2.5 3.5 4.5 5.5];
toeplitz(c,r)
{Warning: First element of input column does not match first element of input row.
Column wins diagonal conflict.}
ans =
1.0000 2.5000 3.5000 4.5000 5.5000
2.0000 1.0000 2.5000 3.5000 4.5000
3.0000 2.0000 1.0000 2.5000 3.5000
4.0000 3.0000 2.0000 1.0000 2.5000
5.0000 4.0000 3.0000 2.0000 1.0000
linspace(-3,5,12)
ans =
Columns 1 through 10
-3.0000 -2.2727 -1.5455 -0.8182 -0.0909 0.6364 1.3636 2.0909 2.8182 3.5455
Columns 11 through 12
4.2727 5.0000
cat(1,A,D)
ans =
0.5377 0.8622 -0.4336
1.8339 0.3188 0.3426
-2.2588 -1.3077 3.5784
0.5377 0 0
0 0.3188 0
0 0 3.5784
cat(2,A,D)
ans =
0.5377 0.8622 -0.4336 0.5377 0 0
1.8339 0.3188 0.3426 0 0.3188 0
-2.2588 -1.3077 3.5784 0 0 3.5784
cat(3,A,D)
ans(:,:,1) =
0.5377 0.8622 -0.4336
1.8339 0.3188 0.3426
-2.2588 -1.3077 3.5784
ans(:,:,2) =
0.5377 0 0
0 0.3188 0
0 0 3.5784
B = repmat(eye(2),3,4)
B =
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
1 0 1 0 1 0 1 0
0 1 0 1 0 1 0 1
B=floor(5*rand(2,4))
B =
4 4 2 0
0 4 4 2
B>2
ans =
1 1 0 0
0 1 1 0
B(ans)
ans =
4
4
4
4
B(B==0)=NaN
B =
4 4 2 NaN
NaN 4 4 2
b=[1 2 3]
b =
1 2 3
b([1 1 1])
ans =
1 1 1
b(logical([1 1 1])) % every element
ans =
1 2 3
B=rand(3)
B =
0.9157 0.6557 0.9340
0.7922 0.0357 0.6787
0.9595 0.8491 0.7577
A*B % matrix multiplication
ans =
0.7594 0.0152 0.7588
2.2606 1.5049 2.1888
0.3290 1.5106 -0.2858
A-3*B
ans =
-2.2095 -1.1050 -3.2356
-0.5427 0.2116 -1.6936
-5.1373 -3.8551 1.3052
A^2
ans =
2.8496 1.3054 -1.4893
0.7967 1.2347 0.5401
-11.6957 -7.0438 13.3363
A.^2
ans =
0.2891 0.7433 0.1880
3.3631 0.1016 0.1174
5.1024 1.7100 12.8049
A.^2 % elementwise
ans =
0.2891 0.7433 0.1880
3.3631 0.1016 0.1174
5.1024 1.7100 12.8049
A=round(randn(3,4))
A =
1 -1 -1 1
0 1 -1 0
0 -1 -3 -1
B=round(randn(3,4))
B =
1 0 -1 1
-2 0 0 1
0 0 0 1
C=A+1i*B
C =
1.0000 + 1.0000i -1.0000 -1.0000 - 1.0000i 1.0000 + 1.0000i
0 - 2.0000i 1.0000 -1.0000 0 + 1.0000i
0 -1.0000 -3.0000 -1.0000 + 1.0000i
C'
ans =
1.0000 - 1.0000i 0 + 2.0000i 0
-1.0000 1.0000 -1.0000
-1.0000 + 1.0000i -1.0000 -3.0000
1.0000 - 1.0000i 0 - 1.0000i -1.0000 - 1.0000i
C' % conjugate transpose
ans =
1.0000 - 1.0000i 0 + 2.0000i 0
-1.0000 1.0000 -1.0000
-1.0000 + 1.0000i -1.0000 -3.0000
1.0000 - 1.0000i 0 - 1.0000i -1.0000 - 1.0000i
A=magic(3)
A =
8 1 6
3 5 7
4 9 2
b=randn(3,1)
b =
-0.8637
0.0774
-1.2141
x=A\b
x =
-0.2159
-0.0737
0.1562
format compact
norm(A*x-b)
ans =
2.3592e-016
eig(A)
ans =
15.0000
4.8990
-4.8990
svd(A)
ans =
15.0000
6.9282
3.4641
A+2 % elementwise
ans =
10 3 8
5 7 9
6 11 4
1./A
ans =
0.1250 1.0000 0.1667
0.3333 0.2000 0.1429
0.2500 0.1111 0.5000
A./A
ans =
1 1 1
1 1 1
1 1 1
A=vander(1:3) % Vandermonde
A =
1 1 1
4 2 1
9 3 1
sparse(A)
ans =
(1,1) 1
(2,1) 4
(3,1) 9
(1,2) 1
(2,2) 2
(3,2) 3
(1,3) 1
(2,3) 1
(3,3) 1
full(ans)
ans =
1 1 1
4 2 1
9 3 1
% spdiags spones sparse
B=bucky
B =
(2,1) 1
(5,1) 1
(6,1) 1
(1,2) 1
(3,2) 1
(11,2) 1
(2,3) 1
(4,3) 1
(16,3) 1
(3,4) 1
(5,4) 1
(21,4) 1
(1,5) 1
(4,5) 1
(26,5) 1
(1,6) 1
(7,6) 1
(10,6) 1
(6,7) 1
(8,7) 1
(30,7) 1
(7,8) 1
(9,8) 1
(42,8) 1
(8,9) 1
(10,9) 1
(38,9) 1
(6,10) 1
(9,10) 1
(12,10) 1
(2,11) 1
(12,11) 1
(15,11) 1
(10,12) 1
(11,12) 1
(13,12) 1
(12,13) 1
(14,13) 1
(37,13) 1
(13,14) 1
(15,14) 1
(33,14) 1
(11,15) 1
(14,15) 1
(17,15) 1
(3,16) 1
(17,16) 1
(20,16) 1
(15,17) 1
(16,17) 1
(18,17) 1
(17,18) 1
(19,18) 1
(32,18) 1
(18,19) 1
(20,19) 1
(53,19) 1
(16,20) 1
(19,20) 1
(22,20) 1
(4,21) 1
(22,21) 1
(25,21) 1
(20,22) 1
(21,22) 1
(23,22) 1
(22,23) 1
(24,23) 1
(52,23) 1
(23,24) 1
(25,24) 1
(48,24) 1
(21,25) 1
(24,25) 1
(27,25) 1
(5,26) 1
(27,26) 1
(30,26) 1
(25,27) 1
(26,27) 1
(28,27) 1
(27,28) 1
(29,28) 1
(47,28) 1
(28,29) 1
(30,29) 1
(43,29) 1
(7,30) 1
(26,30) 1
(29,30) 1
(32,31) 1
(35,31) 1
(54,31) 1
(18,32) 1
(31,32) 1
(33,32) 1
(14,33) 1
(32,33) 1
(34,33) 1
(33,34) 1
(35,34) 1
(36,34) 1
(31,35) 1
(34,35) 1
(56,35) 1
(34,36) 1
(37,36) 1
(40,36) 1
(13,37) 1
(36,37) 1
(38,37) 1
(9,38) 1
(37,38) 1
(39,38) 1
(38,39) 1
(40,39) 1
(41,39) 1
(36,40) 1
(39,40) 1
(57,40) 1
(39,41) 1
(42,41) 1
(45,41) 1
(8,42) 1
(41,42) 1
(43,42) 1
(29,43) 1
(42,43) 1
(44,43) 1
(43,44) 1
(45,44) 1
(46,44) 1
(41,45) 1
(44,45) 1
(58,45) 1
(44,46) 1
(47,46) 1
(50,46) 1
(28,47) 1
(46,47) 1
(48,47) 1
(24,48) 1
(47,48) 1
(49,48) 1
(48,49) 1
(50,49) 1
(51,49) 1
(46,50) 1
(49,50) 1
(59,50) 1
(49,51) 1
(52,51) 1
(55,51) 1
(23,52) 1
(51,52) 1
(53,52) 1
(19,53) 1
(52,53) 1
(54,53) 1
(31,54) 1
(53,54) 1
(55,54) 1
(51,55) 1
(54,55) 1
(60,55) 1
(35,56) 1
(57,56) 1
(60,56) 1
(40,57) 1
(56,57) 1
(58,57) 1
(45,58) 1
(57,58) 1
(59,58) 1
(50,59) 1
(58,59) 1
(60,59) 1
(55,60) 1
(56,60) 1
(59,60) 1
nnz(B)
ans =
180
spy(B)
for ii=1:10,
spy(B^ii);
ii
pause
end
quit