octave:3> A=rand(4) A = 0.23793 0.96505 0.24558 0.13013 0.49199 0.44644 0.17120 0.22674 0.41303 0.17793 0.36987 0.21160 0.64432 0.26521 0.67999 0.84780 octave:4> tril(A) ans = 0.23793 0.00000 0.00000 0.00000 0.49199 0.44644 0.00000 0.00000 0.41303 0.17793 0.36987 0.00000 0.64432 0.26521 0.67999 0.84780 octave:5> tril(A)-diag(diag(A)) ans = 0.00000 0.00000 0.00000 0.00000 0.49199 0.00000 0.00000 0.00000 0.41303 0.17793 0.00000 0.00000 0.64432 0.26521 0.67999 0.00000 octave:6> D=diag(diag(A)) D = Diagonal Matrix 0.23793 0 0 0 0 0.44644 0 0 0 0 0.36987 0 0 0 0 0.84780 octave:7> inv(D)*A ans = 1.00000 4.05597 1.03214 0.54692 1.10203 1.00000 0.38348 0.50788 1.11668 0.48106 1.00000 0.57208 0.76000 0.31283 0.80206 1.00000 octave:8> D\A ans = 1.00000 4.05597 1.03214 0.54692 1.10203 1.00000 0.38348 0.50788 1.11668 0.48106 1.00000 0.57208 0.76000 0.31283 0.80206 1.00000 octave:9> ls 2017-10-16.txt jacobi.m octave:10> help jacobi 'jacobi' is a function from the file /home/accounts/personale/clrmrc90/aa1718/calcolo_numerico2/jacobi.m [x, its, norm_r] = jacobi (A, b, tol, max_its, x0) Compute the solution of A*x=b through the Jacobi method. tol is a vector of two components with the relative and the absolute tolerances (defaults [1e-6, 1e-6]). max_its is the maximum number of iterations (default 100) and x0 the initial solution (default zero). x is the computed solution, its the number of iterations and norm_r the norm of the final residual. Additional help for built-in functions and operators is available in the online version of the manual. Use the command 'doc ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list. octave:11> ls 2017-10-16.txt jacobi.m octave:12> A=rand(4) A = 0.2998528 0.0488113 0.1352657 0.8518925 0.2255744 0.3702321 0.9409553 0.3118592 0.4334212 0.9979016 0.4234071 0.4875793 0.9388845 0.4415462 0.0070269 0.4623118 octave:13> b=rand(2,1) b = 0.632115 0.013822 octave:14> jacobi(A,b) error: jacobi: operator -: nonconformant arguments (op1 is 2x1, op2 is 4x1) error: called from: error: /home/accounts/personale/clrmrc90/aa1718/calcolo_numerico2/jacobi.m at line 26, column 3 octave:14> octave:14> b=rand(4,1) b = 0.54162 0.59886 0.69480 0.43986 octave:15> jacobi(A,b) warning: Raggiunto il numero massimo di iterazioni ans = -2.5796e+55 -3.7703e+55 -3.9535e+55 -2.4520e+55 octave:16> jacobi(A,b,1e-4) warning: Raggiunto il numero massimo di iterazioni ans = -2.5796e+55 -3.7703e+55 -3.9535e+55 -2.4520e+55 octave:17> jacobi(A,b,[],50) warning: Raggiunto il numero massimo di iterazioni ans = -2.6180e+27 -3.8263e+27 -4.0123e+27 -2.4884e+27 octave:18> jacobi(A,b,[],50,[1;1;1;1]) warning: Raggiunto il numero massimo di iterazioni ans = 5.6930e+27 8.3207e+27 8.7251e+27 5.4112e+27 octave:19> A = [2, 1, 0; 1, 2, 1; 0, 1, 2]; octave:20> A A = 2 1 0 1 2 1 0 1 2 octave:21> b = A * ones (3, 1); octave:22> b b = 3 4 3 octave:23> x = jacobi (A, b, 1e-8); octave:24> x x = 1.0000 1.0000 1.0000 octave:25> format long e octave:26> x = jacobi (A, b, 1e-8); octave:27> x x = 1.00000000745058e+00 1.00000001490116e+00 1.00000000745058e+00 octave:28> A = [1, 1, 1; 1, 2, 1; 0, 1, 1]; octave:29> b = A * ones (3, 1); octave:30> [x, it] = jacobi (A, b, 1e-8); warning: Impossibile raggiungere la tolleranza richiesta octave:31> x x = -5.98916301767963e+07 -3.87977300743113e+07 -3.25624208230304e+07 octave:32> it it = 1.00000000000000e+02 octave:33> test jacobi warning: Impossibile raggiungere la tolleranza richiesta PASSES 2 out of 2 tests octave:34> lu('ciao') error: invalid conversion from string to real matrix octave:34> jacobi(rand(4),2) error: jacobi: A(I): index out of bounds; value 2 out of bound 1 error: called from: error: /home/accounts/personale/clrmrc90/aa1718/calcolo_numerico2/jacobi.m at line 32, column 10 octave:34> help gausssidel 'gausssidel' is a function from the file /home/accounts/personale/clrmrc90/aa1718/calcolo_numerico2/gausssidel.m [x, its, norm_r] = gausssidel (A, b, tol, max_its, x0) Compute the solution of A*x=b through the Gauss-Sidel method. tol is a vector of two components with the relative and the absolute tolerances (defaults [1e-6, 1e-6]). max_its is the maximum number of iterations (default 100) and x0 the initial solution (default zero). x is the computed solution, its the number of iterations and norm_r the norm of the final residual. Additional help for built-in functions and operators is available in the online version of the manual. Use the command 'doc ' to search the manual index. Help and information about Octave is also available on the WWW at http://www.octave.org and via the help@octave.org mailing list. octave:35> test gausssidel PASSES 2 out of 2 tests octave:36> A A = 1.00000000000000e+00 1.00000000000000e+00 1.00000000000000e+00 1.00000000000000e+00 2.00000000000000e+00 1.00000000000000e+00 0.00000000000000e+00 1.00000000000000e+00 1.00000000000000e+00 octave:37> format octave:38> A A = 1 1 1 1 2 1 0 1 1 octave:39> A([3,1,2],:) ans = 0 1 1 1 1 1 1 2 1 octave:40> A=A([3,1,2],:) A = 0 1 1 1 1 1 1 2 1 octave:41> tril(A)'==triu(A) ans = 1 1 1 1 1 0 1 1 1 octave:42> A A = 0 1 1 1 1 1 1 2 1 octave:43> diary off