octave:2> A=eye(4) A = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 octave:3> A(3,3)=2 A = 1 0 0 0 0 1 0 0 0 0 2 0 0 0 0 1 octave:4> sparse(A) ans = Compressed Column Sparse (rows = 4, cols = 4, nnz = 4) (1, 1) -> 1 (2, 2) -> 1 (3, 3) -> 2 (4, 4) -> 1 octave:5> B=sparse(A) B = Compressed Column Sparse (rows = 4, cols = 4, nnz = 4) (1, 1) -> 1 (2, 2) -> 1 (3, 3) -> 2 (4, 4) -> 1 octave:6> B(2,3) ans = Compressed Column Sparse (rows = 1, cols = 1, nnz = 0) octave:7> B(2,2) ans = Compressed Column Sparse (rows = 1, cols = 1, nnz = 1) (1, 1) -> 1 octave:8> B(3,3) ans = Compressed Column Sparse (rows = 1, cols = 1, nnz = 1) (1, 1) -> 2 octave:9> v=rand(4,1) v = 0.65107 0.11781 0.74796 0.55288 octave:10> B*v ans = 0.65107 0.11781 1.49592 0.55288 octave:11> A=rand(4) A = 0.365993 0.191837 0.872877 0.293296 0.064147 0.558279 0.498839 0.331543 0.453728 0.568101 0.704364 0.080858 0.643000 0.748292 0.734275 0.951800 octave:12> diag(A) ans = 0.36599 0.55828 0.70436 0.95180 octave:13> diag(diag(A)) ans = 0.36599 0.00000 0.00000 0.00000 0.00000 0.55828 0.00000 0.00000 0.00000 0.00000 0.70436 0.00000 0.00000 0.00000 0.00000 0.95180 octave:14> sparse(diag(diag(A))) ans = Compressed Column Sparse (rows = 4, cols = 4, nnz = 4) (1, 1) -> 0.36599 (2, 2) -> 0.55828 (3, 3) -> 0.70436 (4, 4) -> 0.95180 octave:15> spdiags(diag(A),0,4,4) ans = Compressed Column Sparse (rows = 4, cols = 4, nnz = 4) (1, 1) -> 0.36599 (2, 2) -> 0.55828 (3, 3) -> 0.70436 (4, 4) -> 0.95180 octave:16> A A = 0.365993 0.191837 0.872877 0.293296 0.064147 0.558279 0.498839 0.331543 0.453728 0.568101 0.704364 0.080858 0.643000 0.748292 0.734275 0.951800 octave:17> D=spdiags(diag(A),0,4,4) D = Compressed Column Sparse (rows = 4, cols = 4, nnz = 4) (1, 1) -> 0.36599 (2, 2) -> 0.55828 (3, 3) -> 0.70436 (4, 4) -> 0.95180 octave:18> b=rand(4,1) b = 0.70706 0.16707 0.18121 0.44781 octave:19> A A = 0.365993 0.191837 0.872877 0.293296 0.064147 0.558279 0.498839 0.331543 0.453728 0.568101 0.704364 0.080858 0.643000 0.748292 0.734275 0.951800 octave:20> D\(D-A) ans = 0.00000 -0.52416 -2.38496 -0.80137 -0.11490 0.00000 -0.89353 -0.59386 -0.64417 -0.80654 0.00000 -0.11480 -0.67556 -0.78619 -0.77146 0.00000 octave:21> D\b ans = 1.93191 0.29925 0.25727 0.47049 octave:22> D\[(D-A),b] ans = 0.00000 -0.52416 -2.38496 -0.80137 1.93191 -0.11490 0.00000 -0.89353 -0.59386 0.29925 -0.64417 -0.80654 0.00000 -0.11480 0.25727 -0.67556 -0.78619 -0.77146 0.00000 0.47049 octave:23> A=toeplitz([-4 1 0 0]) A = -4 1 0 0 1 -4 1 0 0 1 -4 1 0 0 1 -4 octave:24> b=rand(4,1) b = 0.59961 0.35510 0.49276 0.62313 octave:25> A\b ans = -0.19856 -0.19463 -0.22484 -0.21199 octave:26> jacobi(A,b,rand(4,1),1e-8,100) ans = -0.19856 -0.19463 -0.22484 -0.21199 octave:27> A=toeplitz([-4 1 0 0 0 0 0]) A = -4 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 -4 1 0 0 0 0 0 1 -4 octave:28> A=sparse(A) A = Compressed Column Sparse (rows = 7, cols = 7, nnz = 19) (1, 1) -> -4 (2, 1) -> 1 (1, 2) -> 1 (2, 2) -> -4 (3, 2) -> 1 (2, 3) -> 1 (3, 3) -> -4 (4, 3) -> 1 (3, 4) -> 1 (4, 4) -> -4 (5, 4) -> 1 (4, 5) -> 1 (5, 5) -> -4 (6, 5) -> 1 (5, 6) -> 1 (6, 6) -> -4 (7, 6) -> 1 (6, 7) -> 1 (7, 7) -> -4 octave:29> jacobi(A,b,rand(4,1),1e-8,100) error: number of rows must match (4 != 7) near line 7, column 12 error: evaluating binary operator `\' near line 7, column 6 error: evaluating assignment expression near line 7, column 3 error: called from `jacobi' in file `/home/accounts/altri/caliari/aa0809/calcolo_numerico/sistemi/jacobi.m' octave:29> b=rand(7,1) b = 0.499726 0.053169 0.373850 0.570001 0.938521 0.795278 0.139071 octave:30> jacobi(A,b,rand(7,1),1e-8,100) ans = -0.149450 -0.098075 -0.189680 -0.286795 -0.387498 -0.324679 -0.115937 octave:31> jacobi(A,b,rand(7,1),1e-8,100) warning: time stamp for `/home/accounts/altri/caliari/aa0809/calcolo_numerico/sistemi/jacobi.m' is in the future ans = -0.149450 -0.098075 -0.189680 -0.286795 -0.387498 -0.324679 -0.115937 octave:32> jacobi(A,b,rand(7,1),1e-8,100) warning: time stamp for `/home/accounts/altri/caliari/aa0809/calcolo_numerico/sistemi/jacobi.m' is in the future ans = -0.149450 -0.098075 -0.189680 -0.286795 -0.387498 -0.324679 -0.115937 octave:33> jacobi(A,b,rand(7,1),1e-8,100) warning: time stamp for `/home/accounts/altri/caliari/aa0809/calcolo_numerico/sistemi/jacobi.m' is in the future ans = -0.149450 -0.098075 -0.189680 -0.286795 -0.387498 -0.324679 -0.115937 octave:34> jacobi(A,b,rand(7,1),1e-8,100) warning: time stamp for `/home/accounts/altri/caliari/aa0809/calcolo_numerico/sistemi/jacobi.m' is in the future ans = -0.149450 -0.098075 -0.189680 -0.286795 -0.387498 -0.324679 -0.115937 octave:35> spdiags([1,2,3],0,3,3) error: invalid vector index = 3 error: evaluating binary operator `+' near line 80, column 14 error: evaluating assignment expression near line 80, column 7 error: evaluating if command near line 57, column 3 error: called from `spdiags' in file `/usr/local/octave-3.0.2/share/octave/3.0.2/m/sparse/spdiags.m' octave:35> spdiags([1,2,3]',0,3,3) ans = Compressed Column Sparse (rows = 3, cols = 3, nnz = 3) (1, 1) -> 1 (2, 2) -> 2 (3, 3) -> 3 octave:36> A=spdiags([1,2,3]',0,3,3) A = Compressed Column Sparse (rows = 3, cols = 3, nnz = 3) (1, 1) -> 1 (2, 2) -> 2 (3, 3) -> 3 octave:37> A(1,2) ans = Compressed Column Sparse (rows = 1, cols = 1, nnz = 0) octave:38> A(1,2)+1 ans = 1 octave:39> A(1,2)*3 ans = Compressed Column Sparse (rows = 1, cols = 1, nnz = 0) octave:40> A(1,2)*3+2 ans = 2 octave:41> A A = Compressed Column Sparse (rows = 3, cols = 3, nnz = 3) (1, 1) -> 1 (2, 2) -> 2 (3, 3) -> 3 octave:42> A=rand(4) A = 0.0465317 0.8254520 0.3613387 0.0021236 0.3638715 0.7549396 0.1809219 0.0676895 0.0642877 0.0707397 0.2219096 0.9761552 0.2337925 0.0958573 0.7168396 0.0855953 octave:43> triu(A) ans = 0.04653 0.82545 0.36134 0.00212 0.00000 0.75494 0.18092 0.06769 0.00000 0.00000 0.22191 0.97616 0.00000 0.00000 0.00000 0.08560 octave:44> tril(A) ans = 0.04653 0.00000 0.00000 0.00000 0.36387 0.75494 0.00000 0.00000 0.06429 0.07074 0.22191 0.00000 0.23379 0.09586 0.71684 0.08560 octave:45> 2/3 ans = 0.66667 octave:46> 3\2 ans = 0.66667 octave:47> diary off