ls=single(1+rand())
ls =
1.9133759
rs=ls+eps(single(ls))
rs =
1.9133760
ld=double(ls)
ld =
1.913375854492188
rd=double(rs)
rd =
1.913375973701477
cnt=0; mark=ld; while( mark <= rd ) cnt=cnt+1; mark=mark+eps(mark); end
cnt
cnt =
536870913
cnt=cnt-2
cnt =
536870911
2^29-1
ans =
536870911
pwd
ans =
/Users/pauldj/works/courses/LSC/LSC-15
ls
ls =
1.9133759
lu(rand(3))
ans =
0.632359246225410 0.546881519204984 0.157613081677548
0.154248404813615 0.873151233474882 0.946281215334096
0.440411396732824 0.829221392263737 0.103075723945612
lu = 4
lu =
4
lu(rand(3))
{Subscript indices must either be real positive integers or logicals.
}
clear('lu')
C=reshape(36,6,6)
{Error using reshape
To RESHAPE the number of elements must not change.
}
C=reshape(1:36,6,6)
C =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
C( 2:3, 2:3 ) = eye(2)
C =
1 7 13 19 25 31
2 1 0 20 26 32
3 0 1 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
C( [2 3 6], [2 3] ) = rand(3,2)
C =
Columns 1 through 3
1.000000000000000 7.000000000000000 13.000000000000000
2.000000000000000 0.849129305868777 0.757740130578333
3.000000000000000 0.933993247757551 0.743132468124916
4.000000000000000 10.000000000000000 16.000000000000000
5.000000000000000 11.000000000000000 17.000000000000000
6.000000000000000 0.678735154857773 0.392227019534168
Columns 4 through 6
19.000000000000000 25.000000000000000 31.000000000000000
20.000000000000000 26.000000000000000 32.000000000000000
21.000000000000000 27.000000000000000 33.000000000000000
22.000000000000000 28.000000000000000 34.000000000000000
23.000000000000000 29.000000000000000 35.000000000000000
24.000000000000000 30.000000000000000 36.000000000000000
format short
C
C =
1.0000 7.0000 13.0000 19.0000 25.0000 31.0000
2.0000 0.8491 0.7577 20.0000 26.0000 32.0000
3.0000 0.9340 0.7431 21.0000 27.0000 33.0000
4.0000 10.0000 16.0000 22.0000 28.0000 34.0000
5.0000 11.0000 17.0000 23.0000 29.0000 35.0000
6.0000 0.6787 0.3922 24.0000 30.0000 36.0000
C( [2 3 6], [2 3] ) = -1
C =
1 7 13 19 25 31
2 -1 -1 20 26 32
3 -1 -1 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 -1 -1 24 30 36
C( 3, : ) = [ 1 2 3 4 5 6 ]
C =
1 7 13 19 25 31
2 -1 -1 20 26 32
1 2 3 4 5 6
4 10 16 22 28 34
5 11 17 23 29 35
6 -1 -1 24 30 36
C( :, 3 ) = []
C =
1 7 19 25 31
2 -1 20 26 32
1 2 4 5 6
4 10 22 28 34
5 11 23 29 35
6 -1 24 30 36
C( end:-3:2, 2:3:end ) = 0
C =
1 7 19 25 31
2 -1 20 26 32
1 0 4 5 0
4 10 22 28 34
5 11 23 29 35
6 0 24 30 0
C( end:-3:2, 2:3:end ) = [1000 1001; 1002 1003]
C =
1 7 19 25 31
2 -1 20 26 32
1 1002 4 5 1003
4 10 22 28 34
5 11 23 29 35
6 1000 24 30 1001
C( end:-3:2, 2:3:end ) = [1000 1001]
{Subscripted assignment dimension mismatch.
}
C( end:-3:2, 2:3:end ) = [1000 1001 1002 1004]
{Subscripted assignment dimension mismatch.
}
C
C =
1 7 19 25 31
2 -1 20 26 32
1 1002 4 5 1003
4 10 22 28 34
5 11 23 29 35
6 1000 24 30 1001
[m,n]=size(C)
m =
6
n =
5
edit
pwd
ans =
/Users/pauldj/works/courses/LSC/LSC-15
script
ans =
1
ans =
7
ans =
19
ans =
25
ans =
31
{Index exceeds matrix dimensions.
Error in script (line 3)
C(i,j)
}
script
{Error: File: script.m Line: 3 Column: 10
Unbalanced or unexpected parenthesis or bracket.
}
script
ans =
1
ans =
7
ans =
19
ans =
25
ans =
31
ans =
2
ans =
-1
ans =
20
ans =
26
ans =
32
ans =
1
ans =
1002
ans =
4
ans =
5
ans =
1003
ans =
4
ans =
10
ans =
22
ans =
28
ans =
34
ans =
5
ans =
11
ans =
23
ans =
29
ans =
35
ans =
6
ans =
1000
ans =
24
ans =
30
ans =
1001
C=reshape(1:36,6,6)
C =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
script
ans =
1 7
2 8
ans =
13 19
14 20
ans =
25 31
26 32
ans =
3 9
4 10
ans =
15 21
16 22
ans =
27 33
28 34
ans =
5 11
6 12
ans =
17 23
18 24
ans =
29 35
30 36
script
ans =
1 7 13
2 8 14
3 9 15
ans =
19 25 31
20 26 32
21 27 33
ans =
4 10 16
5 11 17
6 12 18
ans =
22 28 34
23 29 35
24 30 36
script
ans =
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
{Index exceeds matrix dimensions.
Error in script (line 5)
C(i:i+b-1,j:j+b-1)
}
C
C =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
script
ans =
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
ans =
25 31
26 32
27 33
28 34
ans =
5 11 17 23
6 12 18 24
ans =
29 35
30 36
script
ans =
1 7 13 19 25
2 8 14 20 26
3 9 15 21 27
4 10 16 22 28
ans =
5 11 17 23 29
6 12 18 24 30
C
C =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
m
m =
6
n
n =
5
[m,n]=size(C)
m =
6
n =
6
script
ans =
1 7 13 19 25
2 8 14 20 26
3 9 15 21 27
4 10 16 22 28
ans =
31
32
33
34
ans =
5 11 17 23 29
6 12 18 24 30
ans =
35
36
C
C =
1 7 13 19 25 31
2 8 14 20 26 32
3 9 15 21 27 33
4 10 16 22 28 34
5 11 17 23 29 35
6 12 18 24 30 36
size(C(3:2, 1:3))
ans =
0 3
C(3:2, 1:3)
ans =
Empty matrix: 0-by-3
C(3:2, :)
ans =
Empty matrix: 0-by-6
C(3:2, :) * rand(6,3)
ans =
Empty matrix: 0-by-3
C(3:2, :)'
ans =
Empty matrix: 6-by-0
C(3:2, :)'*C(3:2, :)
ans =
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
0 0 0 0 0 0
C(3:2, :)*C(3:2, :)'
ans =
[]
[C(3:2, :); eye(6)]
ans =
1 0 0 0 0 0
0 1 0 0 0 0
0 0 1 0 0 0
0 0 0 1 0 0
0 0 0 0 1 0
0 0 0 0 0 1
edit MatVec
[W,V]=eig(rand(4))
W =
0.2743 0.5692 -0.4828 -0.0490
0.4924 -0.3102 0.5389 -0.7973
0.7611 0.2512 0.5708 0.5329
0.3211 -0.7188 -0.3882 0.2792
V =
1.9561 0 0 0
0 -0.3914 0 0
0 0 0.4674 0
0 0 0 0.3080
MatVec( eye(5), 1:5 )
{Error: File: MatVec.m Line: 5 Column: 4
This statement is not inside any function.
(It follows the END that terminates the definition of the function
"MatVec".)
}
MatVec( eye(5), 1:5 )
{Error using *
Inner matrix dimensions must agree.
Error in MatVec (line 4)
y = M*v;
}
1:5
ans =
1 2 3 4 5
1:5'
ans =
1 2 3 4 5
(1:5)'
ans =
1
2
3
4
5
MatVec( eye(5), (1:5)' )
ans =
1
2
3
4
5
[output1, output2]=MatVec( eye(5), (1:5)' )
output1 =
1
2
3
4
5
output2 =
5 1
[~, output2]=MatVec( eye(5), (1:5)' )
output2 =
5 1
matrix(4)
M =
0 0 1 1
0 0 1 1
2 3 3 4
2 3 3 4
ans =
0 0 1 1
0 0 1 1
2 3 3 4
2 3 3 4
matrix(8)
M =
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
2 2 3 3 3 3 4 4
2 2 3 3 3 3 4 4
2 2 3 3 3 3 4 4
2 2 3 3 3 3 4 4
ans =
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 0 0 1 1 1 1
0 0 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
18.1182
18.1182
ans =
2.5596
2.5596
2.5596
2.5596
2.5596
2.5596
18.1182
18.1182
18.1182
18.1182
18.1182
18.1182
y=rand(12,1)
y =
0.9293
0.3500
0.1966
0.2511
0.6160
0.4733
0.3517
0.8308
0.5853
0.5497
0.9172
0.2858
matrixV(12,y)
M =
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
x =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
ans =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
sum(y(7:12))
ans =
3.5205
matrixV(12,y)
x =
3.5205
19.2872
ans =
3.5205
19.2872
matrixV(12,y)
x =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
ans =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
matrixV(12,y)
{Undefined function or variable 'xT'.
Error in matrixV (line 12)
x = [xT * ones(h,1) ;
}
matrixV(12,y)
x =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
ans =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
matrixV0(12,y)
M =
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
0 0 0 0 0 0 1 1 1 1 1 1
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
2 2 2 3 3 3 3 3 3 4 4 4
ans =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
matrixV0(12,y)
ans =
3.5205
3.5205
3.5205
3.5205
3.5205
3.5205
19.2872
19.2872
19.2872
19.2872
19.2872
19.2872
n=6000; y=rand(n,1); tic; matrixV0(n,y); toc
Elapsed time is 0.455725 seconds.
clc
clc
n=6000; y=rand(n,1); tic; matrixV0(n,y); toc
Elapsed time is 0.425470 seconds.
n=6000; y=rand(n,1); tic; matrixV0(n,y); toc
Elapsed time is 0.418413 seconds.
n=6000; y=rand(n,1); tic; matrixV0(n,y); toc
Elapsed time is 0.420060 seconds.
n=6000; y=rand(n,1); tic; matrixV(n,y); toc
Elapsed time is 0.000978 seconds.
n=6000; y=rand(n,1); tic; matrixV(n,y); toc
Elapsed time is 0.000230 seconds.
n=6000; y=rand(n,1); tic; matrixV(n,y); toc
Elapsed time is 0.000166 seconds.
n=6000; y=rand(n,1); tic; matrixV(n,y); toc
Elapsed time is 0.000212 seconds.
diary