A = [ 1 2; 1 2]; B = [ A A A ]'; C = [ A; A; A ];
B == C
ans =
1 0
0 1
1 0
0 1
1 0
0 1
find( B == C )
ans =
1
3
5
8
10
12
B > 1.5
ans =
0 0
1 1
0 0
1 1
0 0
1 1
find( B > C )
ans =
2
4
6
idx = find( B > C )
idx =
2
4
6
[row, col] = find( B > C )
row =
2
4
6
col =
1
1
1
diag( [ 1 2 3 4] )
ans =
1 0 0 0
0 2 0 0
0 0 3 0
0 0 0 4
M = rand(4)
M =
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
diag( M )
ans =
0.8147
0.0975
0.1576
0.1419
diag(diag( M ))
ans =
0.8147 0 0 0
0 0.0975 0 0
0 0 0.1576 0
0 0 0 0.1419
M(:, :)
ans =
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
eye(4)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
M * eye(4)
ans =
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
eye(4) * M
ans =
0.8147 0.6324 0.9575 0.9572
0.9058 0.0975 0.9649 0.4854
0.1270 0.2785 0.1576 0.8003
0.9134 0.5469 0.9706 0.1419
eye(4) .* M
ans =
0.8147 0 0 0
0 0.0975 0 0
0 0 0.1576 0
0 0 0 0.1419
M .* eye(4)
ans =
0.8147 0 0 0
0 0.0975 0 0
0 0 0.1576 0
0 0 0 0.1419
diag( [1 2 3], -2 )
ans =
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 2 0 0 0
0 0 3 0 0
M = diag( [1 2 3], -2 )
M =
0 0 0 0 0
0 0 0 0 0
1 0 0 0 0
0 2 0 0 0
0 0 3 0 0
M = M + diag( [4 5], 3 )
M =
0 0 0 4 0
0 0 0 0 5
1 0 0 0 0
0 2 0 0 0
0 0 3 0 0
A = [ 1 2; 3 4 ];
M = [ A 2*A 3*A; 10*A 20*A 30*A; 100*A 200*A 300*A ];
size(M)
ans =
6 6
M
M =
1 2 2 4 3 6
3 4 6 8 9 12
10 20 20 40 30 60
30 40 60 80 90 120
100 200 200 400 300 600
300 400 600 800 900 1200
b=2; n=6; for i=1:b:n, for j=1:b:n, M(i:i+b-1, j:j+b-1), end, end
ans =
1 2
3 4
ans =
2 4
6 8
ans =
3 6
9 12
ans =
10 20
30 40
ans =
20 40
60 80
ans =
30 60
90 120
ans =
100 200
300 400
ans =
200 400
600 800
ans =
300 600
900 1200
M
M =
1 2 2 4 3 6
3 4 6 8 9 12
10 20 20 40 30 60
30 40 60 80 90 120
100 200 200 400 300 600
300 400 600 800 900 1200
b=3; n=6; for i=1:b:n, for j=1:b:n, M(i:i+b-1, j:j+b-1), end, end
ans =
1 2 2
3 4 6
10 20 20
ans =
4 3 6
8 9 12
40 30 60
ans =
30 40 60
100 200 200
300 400 600
ans =
80 90 120
400 300 600
800 900 1200
M
M =
1 2 2 4 3 6
3 4 6 8 9 12
10 20 20 40 30 60
30 40 60 80 90 120
100 200 200 400 300 600
300 400 600 800 900 1200
b=4; n=6; for i=1:b:n, for j=1:b:n, M(i:i+b-1, j:j+b-1), end, end
ans =
1 2 2 4
3 4 6 8
10 20 20 40
30 40 60 80
{??? Index exceeds matrix dimensions.
}
b=4; n=6; for i=1:b:n, for j=1:b:n, M(i:min(end,i+b-1), j:min(end,j+b-1)), end, end
ans =
1 2 2 4
3 4 6 8
10 20 20 40
30 40 60 80
ans =
3 6
9 12
30 60
90 120
ans =
100 200 200 400
300 400 600 800
ans =
300 600
900 1200
b=5; n=6; for i=1:b:n, for j=1:b:n, M(i:min(end,i+b-1), j:min(end,j+b-1)), end, end
ans =
1 2 2 4 3
3 4 6 8 9
10 20 20 40 30
30 40 60 80 90
100 200 200 400 300
ans =
6
12
60
120
600
ans =
300 400 600 800 900
ans =
1200
1:10
ans =
1 2 3 4 5 6 7 8 9 10
1:12
ans =
1 2 3 4 5 6 7 8 9 10 11 12
reshape(1:12,3,4)
ans =
1 4 7 10
2 5 8 11
3 6 9 12
reshape(1:12,4,3)
ans =
1 5 9
2 6 10
3 7 11
4 8 12
reshape(1:12,2,3,2)
ans(:,:,1) =
1 3 5
2 4 6
ans(:,:,2) =
7 9 11
8 10 12
M
M =
1 2 2 4 3 6
3 4 6 8 9 12
10 20 20 40 30 60
30 40 60 80 90 120
100 200 200 400 300 600
300 400 600 800 900 1200
M( 3, 2:3 )
ans =
20 20
M( 3, [3 4] )
ans =
20 40
M( 3, 5:5 )
ans =
30
M( 3, [5 5] )
ans =
30 30
M( 3, [1 2 3 4 4 5 5 5 2 3 4 5 )
??? M( 3, [1 2 3 4 4 5 5 5 2 3 4 5 )
|
{Error: Unbalanced or unexpected parenthesis or bracket.
}
M( 3, [1 2 3 4 4 5 5 5 2 3 4 5] )
ans =
10 20 20 40 40 30 30 30 20 20 40 30
A = [ 1:3 2:4 ]; B = A(:); C = B( [2:3 3:4] );
C = [C [A; A]]
{??? Error using ==> horzcat
CAT arguments dimensions are not consistent.
}
[A; A]
ans =
1 2 3 2 3 4
1 2 3 2 3 4
C
C =
2
3
3
2
C = [C [A; A; A; A]]
C =
2 1 2 3 2 3 4
3 1 2 3 2 3 4
3 1 2 3 2 3 4
2 1 2 3 2 3 4
v = 1:10
v =
1 2 3 4 5 6 7 8 9 10
v( 1:2:end )
ans =
1 3 5 7 9
v( 1:2:end ) = rand(5,1)
v =
Columns 1 through 8
0.4218 2.0000 0.9157 4.0000 0.7922 6.0000 0.9595 8.0000
Columns 9 through 10
0.6557 10.0000
v( 1:2:end ) = rand(1,5)
v =
Columns 1 through 8
0.0357 2.0000 0.8491 4.0000 0.9340 6.0000 0.6787 8.0000
Columns 9 through 10
0.7577 10.0000
v( 1:2:end ) = 0
v =
0 2 0 4 0 6 0 8 0 10
v = 1:10
v =
1 2 3 4 5 6 7 8 9 10
v( end:-2:1 ) = v( 3:8 )
{??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
}
v( end:-2:1 ) = v( 3:7 )
v =
1 7 3 6 5 5 7 4 9 3
v( end:-2:1 ) = v( 3:8 )
{??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
}
v = 1:10
v =
1 2 3 4 5 6 7 8 9 10
v( 8:12 ) = 1:5
v =
1 2 3 4 5 6 7 1 2 3 4 5
v( 13 )
{??? Attempted to access v(13); index out of bounds because numel(v)=12.
}
v( 0 )
{??? Attempted to access v(0); index must be a positive integer or logical.
}
v( -1 )
{??? Attempted to access v(-1); index must be a positive integer or logical.
}
edit
pwd
ans =
/Users/pauldj/Documents/MATLAB
ls
H.m distr.m strassen.m
Yurii.m my_chol.m trsm.m
createfigure.m p_dj.m yulia.m
diary rand_16_1024.mat yulia.m~
diary_part1 rand_3.mat
diary_part1~ script.m
script
ans =
1 3 5 7 9
2 4 6 8 10
FunName( 4 )
out =
1 3 5 7 9
2 4 6 8 10
ans =
1 3 5 7 9
2 4 6 8 10
FunName( 4 );
out =
1 3 5 7 9
2 4 6 8 10
FunName( 4 );
out = FunName( 4 );
out
out =
1 3 5 7 9
2 4 6 8 10
out = FunName( 4 );
out = FunName( 4 )
out =
1 3
2 4
out = FunName( 10 )
out =
1 3 5 7 9
2 4 6 8 10
out = FunName( 11 )
{??? Error using ==> reshape
Size arguments must be real integers.
Error in ==> FunName at 4
out = reshape(v,2,arg/2);
}
out = FunName( 11 )
out =
1 2 3 4 5 6 7 8 9 10 11
FunName( 11 )
ans =
1 2 3 4 5 6 7 8 9 10 11
[list1, list2] = FunName( 11 )
list1 =
1 2 3 4 5 6 7 8 9 10 11
list2 =
11 9 7 5 3 1
[list1, list2] = FunName( 11 )
list1 =
1 2 3 4 5 6 7 8 9 10 11
list2 =
11
9
7
5
3
1
M = rand(5); M = M+M';
eig(M)
ans =
-1.1450
-0.4698
0.3601
1.2398
4.8812
e = eig(M)
e =
-1.1450
-0.4698
0.3601
1.2398
4.8812
[V,E] = eig(M)
V =
0.1655 0.0750 0.7692 -0.3797 0.4808
0.5006 -0.5309 0.0336 0.5984 0.3292
0.0990 -0.2084 -0.6047 -0.5334 0.5446
0.2594 0.8142 -0.1998 0.3205 0.3565
-0.8031 -0.0782 0.0404 0.3325 0.4866
E =
-1.1450 0 0 0 0
0 -0.4698 0 0 0
0 0 0.3601 0 0
0 0 0 1.2398 0
0 0 0 0 4.8812
V'*E*V - M
ans =
1.5996 0.2476 -1.7481 -1.8409 -3.0935
0.2476 0.1747 -0.5927 -0.4442 -1.2957
-1.7481 -0.5927 -2.3892 -0.4024 -1.6878
-1.8409 -0.4442 -0.4024 0.0625 -0.3012
-3.0935 -1.2957 -1.6878 -0.3012 0.5524
V*E*V' - M
ans =
1.0e-14 *
-0.0666 -0.0111 -0.0888 -0.0222 -0.1110
0 -0.0222 -0.0333 -0.0666 -0.1332
-0.0888 -0.0333 -0.1554 -0.0666 -0.1332
-0.0222 -0.0777 -0.0666 -0.0444 -0.1110
-0.1110 -0.1332 -0.1554 -0.1332 0.1110
norm(V*E*V' - M)
ans =
3.7559e-15
norm(V*E*V' - M)/norm(M)
ans =
7.6946e-16
help lu
LU LU factorization.
[L,U] = LU(A) stores an upper triangular matrix in U and a
"psychologically lower triangular matrix" (i.e. a product of lower
triangular and permutation matrices) in L, so that A = L*U. A can be
rectangular.
[L,U,P] = LU(A) returns unit lower triangular matrix L, upper
triangular matrix U, and permutation matrix P so that P*A = L*U.
[L,U,p] = LU(A,'vector') returns the permutation information as a
vector instead of a matrix. That is, p is a row vector such that
A(p,:) = L*U. Similarly, [L,U,P] = LU(A,'matrix') returns a
permutation matrix P. This is the default behavior.
Y = LU(A) returns the output from LAPACK'S DGETRF or ZGETRF routine if
A is full. If A is sparse, Y contains the strict lower triangle of L
embedded in the same matrix as the upper triangle of U. In both full
and sparse cases, the permutation information is lost.
[L,U,P,Q] = LU(A) returns unit lower triangular matrix L, upper
triangular matrix U, a permutation matrix P and a column reordering
matrix Q so that P*A*Q = L*U for sparse non-empty A. This uses UMFPACK
and is significantly more time and memory efficient than the other
syntaxes, even when used with COLAMD.
[L,U,p,q] = LU(A,'vector') returns two row vectors p and q so that
A(p,q) = L*U. Using 'matrix' in place of 'vector' returns permutation
matrices.
[L,U,P,Q,R] = LU(A) returns unit lower triangular matrix L, upper
triangular matrix U, permutation matrices P and Q, and a diagonal
scaling matrix R so that P*(R\A)*Q = L*U for sparse non-empty A.
This uses UMFPACK as well. Typically, but not always, the row-scaling
leads to a sparser and more stable factorization. Note that this
factorization is the same as that used by sparse MLDIVIDE when
UMFPACK is used.
[L,U,p,q,R] = LU(A,'vector') returns the permutation information in two
row vectors p and q such that R(:,p)\A(:,q) = L*U. Using 'matrix'
in place of 'vector' returns permutation matrices.
[L,U,P] = LU(A,THRESH) controls pivoting in sparse matrices, where
THRESH is a pivot threshold in [0,1]. Pivoting occurs when the
diagonal entry in a column has magnitude less than THRESH times the
magnitude of any sub-diagonal entry in that column. THRESH = 0 forces
diagonal pivoting. THRESH = 1 is the default.
[L,U,P,Q,R] = LU(A,THRESH) controls pivoting in UMFPACK. THRESH is a
one or two element vector which defaults to [0.1 0.001]. If UMFPACK
selects its unsymmetric pivoting strategy, THRESH(2) is not used. It
uses its symmetric pivoting strategy if A is square with a mostly
symmetric nonzero structure and a mostly nonzero diagonal. For its
unsymmetric strategy, the sparsest row i which satisfies the criterion
A(i,j) >= THRESH(1) * max(abs(A(j:m,j))) is selected. A value of 1.0
results in conventional partial pivoting. Entries in L have absolute
value of 1/THRESH(1) or less. For its symmetric strategy, the diagonal
is selected using the same test but with THRESH(2) instead. If the
diagonal entry fails this test, a pivot entry below the diagonal is
selected, using THRESH(1). In this case, L has entries with absolute
value 1/min(THRESH) or less. Smaller values of THRESH(1) and THRESH(2)
tend to lead to sparser LU factors, but the solution can become
inaccurate. Larger values can lead to a more accurate solution (but
not always), and usually an increase in the total work and memory
usage.
[L,U,p] = LU(A,THRESH,'vector') and [L,U,p,q,R] = LU(A,THRESH,'vector')
are also valid for sparse matrices and return permutation vectors.
Using 'matrix' in place of 'vector' returns permutation matrices.
See also colamd, luinc, qr, rref, umfpack.
Overloaded methods:
gf/lu
distributed/lu
codistributed/lu
Reference page in Help browser
doc lu
6/3
ans =
2
A = [ 1 2; 5 3 ];
B = [2; -1];
A
A =
1 2
5 3
b = [2; -1];
b
b =
2
-1
b/A
{??? Error using ==> mrdivide
Matrix dimensions must agree.
}
A\b
ans =
-1.1429
1.5714
inv(A) * b
ans =
-1.1429
1.5714
sol1 = A\b
sol1 =
-1.1429
1.5714
sol2 = inv(A) * b
sol2 =
-1.1429
1.5714
norm(sol1 - sol2)
ans =
2.2204e-16
norm(sol1 - sol2)/norm(sol1)
ans =
1.1428e-16
M = rand(5)
M =
0.6797 0.9597 0.2551 0.5472 0.2543
0.6551 0.3404 0.5060 0.1386 0.8143
0.1626 0.5853 0.6991 0.1493 0.2435
0.1190 0.2238 0.8909 0.2575 0.9293
0.4984 0.7513 0.9593 0.8407 0.3500
M = rand(5); N = rand(5);
M\N
ans =
2.0229 1.0938 3.2464 0.1004 1.6023
0.0267 -0.7304 -1.2989 -1.3852 2.0791
0.5928 -0.1478 0.1947 0.6094 -1.1107
-1.2291 0.5874 -0.5842 0.6693 -1.1922
-0.0143 1.2921 0.7189 2.0603 -0.3080
M/N
ans =
-0.2834 -0.0041 1.2195 0.3739 -0.4710
-0.8494 0.6540 -1.4975 0.4487 2.3910
0.6310 0.7928 1.4433 -0.7368 -1.2835
-0.0047 0.8834 0.4985 0.0689 -0.1209
0.8158 -0.0554 1.9732 -0.4213 -2.0801
M = rand(10,5)
M =
0.0844 0.8693 0.2399 0.3377 0.9421
0.3998 0.5797 0.1233 0.9001 0.9561
0.2599 0.5499 0.1839 0.3692 0.5752
0.8001 0.1450 0.2400 0.1112 0.0598
0.4314 0.8530 0.4173 0.7803 0.2348
0.9106 0.6221 0.0497 0.3897 0.3532
0.1818 0.3510 0.9027 0.2417 0.8212
0.2638 0.5132 0.9448 0.4039 0.0154
0.1455 0.4018 0.4909 0.0965 0.0430
0.1361 0.0760 0.4893 0.1320 0.1690
M \ [1:5]
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ 1:5
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ 1:5'
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ [1 2 3 4 5]'
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ 1:10'
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ [1:10]'
ans =
4.8438
0.9577
9.4530
-1.1833
-1.2260
M = rand(5)
M =
0.6491 0.2963 0.3685 0.7757 0.5085
0.7317 0.7447 0.6256 0.4868 0.5108
0.6477 0.1890 0.7802 0.4359 0.8176
0.4509 0.6868 0.0811 0.4468 0.7948
0.5470 0.1835 0.9294 0.3063 0.6443
M \ [1:5]'
ans =
-27.9327
8.0354
12.1449
11.8784
6.0197
x = M \ [1:5]'
x =
-27.9327
8.0354
12.1449
11.8784
6.0197
norm( A*x - [1:5]' )
{??? Error using ==> mtimes
Inner matrix dimensions must agree.
}
A*x
{??? Error using ==> mtimes
Inner matrix dimensions must agree.
}
norm( M*x - [1:5]' )
ans =
4.8850e-15
norm( (M*x - [1:5]')/norm(M) )
ans =
1.7641e-15
M = rand(5,10)
M =
Columns 1 through 8
0.3786 0.8759 0.3012 0.2259 0.9234 0.4389 0.2622 0.2967
0.8116 0.5502 0.4709 0.1707 0.4302 0.1111 0.6028 0.3188
0.5328 0.6225 0.2305 0.2277 0.1848 0.2581 0.7112 0.4242
0.3507 0.5870 0.8443 0.4357 0.9049 0.4087 0.2217 0.5079
0.9390 0.2077 0.1948 0.3111 0.9797 0.5949 0.1174 0.0855
Columns 9 through 10
0.2625 0.4886
0.8010 0.5785
0.0292 0.2373
0.9289 0.4588
0.7303 0.9631
x = M \ [1:5]'
x =
-0.8889
0
0
0
-8.3548
17.2531
0.5875
0
5.0492
0
doc sparse
Overloaded functions or methods (ones with the same name in other directories)
doc distcomp/sparse
sparse(M)
ans =
(1,1) 0.3786
(2,1) 0.8116
(3,1) 0.5328
(4,1) 0.3507
(5,1) 0.9390
(1,2) 0.8759
(2,2) 0.5502
(3,2) 0.6225
(4,2) 0.5870
(5,2) 0.2077
(1,3) 0.3012
(2,3) 0.4709
(3,3) 0.2305
(4,3) 0.8443
(5,3) 0.1948
(1,4) 0.2259
(2,4) 0.1707
(3,4) 0.2277
(4,4) 0.4357
(5,4) 0.3111
(1,5) 0.9234
(2,5) 0.4302
(3,5) 0.1848
(4,5) 0.9049
(5,5) 0.9797
(1,6) 0.4389
(2,6) 0.1111
(3,6) 0.2581
(4,6) 0.4087
(5,6) 0.5949
(1,7) 0.2622
(2,7) 0.6028
(3,7) 0.7112
(4,7) 0.2217
(5,7) 0.1174
(1,8) 0.2967
(2,8) 0.3188
(3,8) 0.4242
(4,8) 0.5079
(5,8) 0.0855
(1,9) 0.2625
(2,9) 0.8010
(3,9) 0.0292
(4,9) 0.9289
(5,9) 0.7303
(1,10) 0.4886
(2,10) 0.5785
(3,10) 0.2373
(4,10) 0.4588
(5,10) 0.9631
spM = sparse(M)
spM =
(1,1) 0.3786
(2,1) 0.8116
(3,1) 0.5328
(4,1) 0.3507
(5,1) 0.9390
(1,2) 0.8759
(2,2) 0.5502
(3,2) 0.6225
(4,2) 0.5870
(5,2) 0.2077
(1,3) 0.3012
(2,3) 0.4709
(3,3) 0.2305
(4,3) 0.8443
(5,3) 0.1948
(1,4) 0.2259
(2,4) 0.1707
(3,4) 0.2277
(4,4) 0.4357
(5,4) 0.3111
(1,5) 0.9234
(2,5) 0.4302
(3,5) 0.1848
(4,5) 0.9049
(5,5) 0.9797
(1,6) 0.4389
(2,6) 0.1111
(3,6) 0.2581
(4,6) 0.4087
(5,6) 0.5949
(1,7) 0.2622
(2,7) 0.6028
(3,7) 0.7112
(4,7) 0.2217
(5,7) 0.1174
(1,8) 0.2967
(2,8) 0.3188
(3,8) 0.4242
(4,8) 0.5079
(5,8) 0.0855
(1,9) 0.2625
(2,9) 0.8010
(3,9) 0.0292
(4,9) 0.9289
(5,9) 0.7303
(1,10) 0.4886
(2,10) 0.5785
(3,10) 0.2373
(4,10) 0.4588
(5,10) 0.9631
size(M)
ans =
5 10
M = rand(5)
M =
0.5468 0.6791 0.8852 0.3354 0.6538
0.5211 0.3955 0.9133 0.6797 0.4942
0.2316 0.3674 0.7962 0.1366 0.7791
0.4889 0.9880 0.0987 0.7212 0.7150
0.6241 0.0377 0.2619 0.1068 0.9037
M < .8
ans =
1 1 0 1 1
1 1 0 1 1
1 1 1 1 1
1 0 1 1 1
1 1 1 1 0
spM (M (M < .8) )
{??? Subscript indices must either be real positive integers or logicals.
}
find(M < .8)
ans =
1
2
3
4
5
6
7
8
10
13
14
15
16
17
18
19
20
21
22
23
24
idx = find(M < .8)
idx =
1
2
3
4
5
6
7
8
10
13
14
15
16
17
18
19
20
21
22
23
24
M(idx) = 0
M =
0 0 0.8852 0 0
0 0 0.9133 0 0
0 0 0 0 0
0 0.9880 0 0 0
0 0 0 0 0.9037
sparse(M)
ans =
(4,2) 0.9880
(1,3) 0.8852
(2,3) 0.9133
(5,5) 0.9037
M \ [1:5]
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ [1:5']
{??? Error using ==> mldivide
Matrix dimensions must agree.
}
M \ [1:5]'
{Warning: Matrix is singular to working precision.}
ans =
NaN
NaN
NaN
Inf
5.5327
M
M =
0 0 0.8852 0 0
0 0 0.9133 0 0
0 0 0 0 0
0 0.9880 0 0 0
0 0 0 0 0.9037
whos('M')
Name Size Bytes Class Attributes
M 5x5 200 double
M = sparse(M)
M =
(4,2) 0.9880
(1,3) 0.8852
(2,3) 0.9133
(5,5) 0.9037
whos('M')
Name Size Bytes Class Attributes
M 5x5 72 double sparse
M \ [1:5]'
{Warning: Matrix is singular to working precision.}
ans =
Inf
4.0487
1.1297
Inf
5.5327
diary