octave:3> pwd ans = /home/accounts/personale/clrmrc90/aa1617/equazioni_differenziali octave:4> ls 2016-10-05.txt octave:5> A=rand(4) A = 0.84162 0.89496 0.41143 0.71012 0.40973 0.70728 0.85371 0.61623 0.60852 0.33947 0.81357 0.19469 0.75518 0.84450 0.56680 0.63074 octave:6> A=2*rand(4)-1 A = 0.644501 -0.849036 -0.779122 0.023192 0.801330 -0.727701 0.401724 -0.373964 -0.695368 0.484875 -0.868256 0.677765 -0.900500 0.655532 -0.640199 0.863349 octave:7> A=randn(4) A = -0.33270 1.73008 0.52745 -0.13165 -0.97765 -1.22221 2.31027 -1.07097 0.65830 -1.83765 -0.14340 -0.43291 -0.54161 0.18578 -1.01630 0.95472 octave:8> b=A*ones(4,1); octave:9> x=A\b x = 1.00000 1.00000 1.00000 1.00000 octave:10> A/b error: operator /: nonconformant arguments (op1 is 4x4, op2 is 4x1) octave:10> [L,U]=lu(A) L = 0.34031 -0.80658 -0.47890 1.00000 1.00000 0.00000 0.00000 0.00000 -0.67335 1.00000 0.00000 0.00000 0.55400 -0.32432 1.00000 0.00000 U = -0.97765 -1.22221 2.31027 -1.07097 0.00000 -2.66062 1.41222 -1.15404 0.00000 0.00000 -1.83818 1.17376 0.00000 0.00000 0.00000 -0.13590 octave:11> L*U ans = -0.33270 1.73008 0.52745 -0.13165 -0.97765 -1.22221 2.31027 -1.07097 0.65830 -1.83765 -0.14340 -0.43291 -0.54161 0.18578 -1.01630 0.95472 octave:12> A A = -0.33270 1.73008 0.52745 -0.13165 -0.97765 -1.22221 2.31027 -1.07097 0.65830 -1.83765 -0.14340 -0.43291 -0.54161 0.18578 -1.01630 0.95472 octave:13> A-L*U ans = 0.0000e+00 0.0000e+00 -1.1102e-16 2.7756e-17 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 8.3267e-17 5.5511e-17 0.0000e+00 -1.3878e-16 -2.2204e-16 1.1102e-16 octave:14> norm(A-L*U) ans = 3.0531e-16 octave:15> L L = 0.34031 -0.80658 -0.47890 1.00000 1.00000 0.00000 0.00000 0.00000 -0.67335 1.00000 0.00000 0.00000 0.55400 -0.32432 1.00000 0.00000 octave:16> U U = -0.97765 -1.22221 2.31027 -1.07097 0.00000 -2.66062 1.41222 -1.15404 0.00000 0.00000 -1.83818 1.17376 0.00000 0.00000 0.00000 -0.13590 octave:17> [L,U,P]=lu(A) L = 1.00000 0.00000 0.00000 0.00000 -0.67335 1.00000 0.00000 0.00000 0.55400 -0.32432 1.00000 0.00000 0.34031 -0.80658 -0.47890 1.00000 U = -0.97765 -1.22221 2.31027 -1.07097 0.00000 -2.66062 1.41222 -1.15404 0.00000 0.00000 -1.83818 1.17376 0.00000 0.00000 0.00000 -0.13590 P = Permutation Matrix 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 octave:18> P*A ans = -0.97765 -1.22221 2.31027 -1.07097 0.65830 -1.83765 -0.14340 -0.43291 -0.54161 0.18578 -1.01630 0.95472 -0.33270 1.73008 0.52745 -0.13165 octave:19> L*U ans = -0.97765 -1.22221 2.31027 -1.07097 0.65830 -1.83765 -0.14340 -0.43291 -0.54161 0.18578 -1.01630 0.95472 -0.33270 1.73008 0.52745 -0.13165 octave:20> U\(L\(P*b)) ans = 1.00000 1.00000 1.00000 1.00000 octave:21> help lu 'lu' is a built-in function from the file libinterp/corefcn/lu.cc -- Built-in Function: [L, U] = lu (A) -- Built-in Function: [L, U, P] = lu (A) -- Built-in Function: [L, U, P, Q] = lu (S) -- Built-in Function: [L, U, P, Q, R] = lu (S) -- Built-in Function: [...] = lu (S, THRES) -- Built-in Function: Y = lu (...) -- Built-in Function: [...] = lu (..., "vector") Compute the LU decomposition of A. If A is full subroutines from LAPACK are used and if A is sparse then UMFPACK is used. The result is returned in a permuted form, according to the optional return value P. For example, given the matrix 'a = [1, 2; 3, 4]', [l, u, p] = lu (A) returns l = 1.00000 0.00000 0.33333 1.00000 u = 3.00000 4.00000 0.00000 0.66667 p = 0 1 1 0 The matrix is not required to be square. When called with two or three output arguments and a spare input matrix, 'lu' does not attempt to perform sparsity preserving column permutations. Called with a fourth output argument, the sparsity preserving column transformation Q is returned, such that 'P * A * Q = L * U'. Called with a fifth output argument and a sparse input matrix, 'lu' attempts to use a scaling factor R on the input matrix such that 'P * (R \ A) * Q = L * U'. This typically leads to a sparser and more stable factorization. An additional input argument THRES, that defines the pivoting threshold can be given. THRES can be a scalar, in which case it defines the UMFPACK pivoting tolerance for both symmetric and unsymmetric cases. If THRES is a 2-element vector, then the first element defines the pivoting tolerance for the unsymmetric UMFPACK pivoting strategy and the second for the symmetric strategy. By default, the values defined by 'spparms' are used ([0.1, 0.001]). Given the string argument "vector", 'lu' returns the values of P and Q as vector values, such that for full matrix, 'A (P,:) = L * U', and 'R(P,:) * A (:, Q) = L * U'. With two output arguments, returns the permuted forms of the upper and lower triangular matrices, such that 'A = L * U'. With one output argument Y, then the matrix returned by the LAPACK routines is returned. If the input matrix is sparse then the matrix L is embedded into U to give a return value similar to the full case. For both full and sparse matrices, 'lu' loses the permutation information. See also: luupdate, chol, hess, qr, qz, schur, svd. 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:22> P P = Permutation Matrix 0 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 octave:23> whos Variables in the current scope: Attr Name Size Bytes Class ==== ==== ==== ===== ===== A 4x4 128 double L 4x4 128 double P 4x4 16 double U 4x4 128 double ans 4x1 32 double b 4x1 32 double x 4x1 32 double Total is 76 elements using 496 bytes octave:24> [L,U,p]=lu(A,'vector') L = 1.00000 0.00000 0.00000 0.00000 -0.67335 1.00000 0.00000 0.00000 0.55400 -0.32432 1.00000 0.00000 0.34031 -0.80658 -0.47890 1.00000 U = -0.97765 -1.22221 2.31027 -1.07097 0.00000 -2.66062 1.41222 -1.15404 0.00000 0.00000 -1.83818 1.17376 0.00000 0.00000 0.00000 -0.13590 p = 2 3 4 1 octave:25> whos Variables in the current scope: Attr Name Size Bytes Class ==== ==== ==== ===== ===== A 4x4 128 double L 4x4 128 double P 4x4 16 double U 4x4 128 double ans 4x1 32 double b 4x1 32 double p 4x1 32 double x 4x1 32 double Total is 80 elements using 528 bytes octave:26> P*b ans = -0.96055 -1.75566 -0.41741 1.79317 octave:27> b(p) ans = -0.96055 -1.75566 -0.41741 1.79317 octave:28> b b = 1.79317 -0.96055 -1.75566 -0.41741 octave:29> b([1,2]) ans = 1.79317 -0.96055 octave:30> b([1,3]) ans = 1.7932 -1.7557 octave:31> b([1,3,2]) ans = 1.79317 -1.75566 -0.96055 octave:32> b([4,1,3,2]) ans = -0.41741 1.79317 -1.75566 -0.96055 octave:33> p p = 2 3 4 1 octave:34> b(p) ans = -0.96055 -1.75566 -0.41741 1.79317 octave:35> P*b ans = -0.96055 -1.75566 -0.41741 1.79317 octave:36> U\(L\(b(p))) ans = 1.00000 1.00000 1.00000 1.00000 octave:37> chol(A) error: chol: input matrix must be positive definite octave:37> B=A*A' B = 3.39939 -0.42969 -3.41693 -0.16012 -0.42969 8.93392 1.73474 -3.06796 -3.41693 1.73474 4.01829 -0.96552 -0.16012 -3.06796 -0.96552 2.27222 octave:38> B-B' ans = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 octave:39> eig(B) ans = 4.8882e-03 1.2267e+00 6.4147e+00 1.0978e+01 octave:40> R=chol(B) R = 1.84374 -0.23306 -1.85326 -0.08685 0.00000 2.97987 0.43721 -1.03636 0.00000 0.00000 0.62655 -1.07471 0.00000 0.00000 0.00000 0.18877 octave:41> R'*R ans = 3.39939 -0.42969 -3.41693 -0.16012 -0.42969 8.93392 1.73474 -3.06796 -3.41693 1.73474 4.01829 -0.96552 -0.16012 -3.06796 -0.96552 2.27222 octave:42> B B = 3.39939 -0.42969 -3.41693 -0.16012 -0.42969 8.93392 1.73474 -3.06796 -3.41693 1.73474 4.01829 -0.96552 -0.16012 -3.06796 -0.96552 2.27222 octave:43> R*R' ans = 6.895816 -1.414735 -1.067821 -0.016394 -1.414735 10.144790 1.387721 -0.195632 -1.067821 1.387721 1.547575 -0.202873 -0.016394 -0.195632 -0.202873 0.035634 octave:44> help chol 'chol' is a function from the file /usr/lib/x86_64-linux-gnu/octave/3.8.1/oct/x86_64-pc-linux-gnu/chol.oct -- Loadable Function: R = chol (A) -- Loadable Function: [R, P] = chol (A) -- Loadable Function: [R, P, Q] = chol (S) -- Loadable Function: [R, P, Q] = chol (S, "vector") -- Loadable Function: [L, ...] = chol (..., "lower") -- Loadable Function: [L, ...] = chol (..., "upper") Compute the Cholesky factor, R, of the symmetric positive definite matrix A, where R' * R = A. Called with one output argument 'chol' fails if A or S is not positive definite. With two or more output arguments P flags whether the matrix was positive definite and 'chol' does not fail. A zero value indicated that the matrix was positive definite and the R gives the factorization, and P will have a positive value otherwise. If called with 3 outputs then a sparsity preserving row/column permutation is applied to A prior to the factorization. That is R is the factorization of 'A(Q,Q)' such that R' * R = Q' * A * Q. The sparsity preserving permutation is generally returned as a matrix. However, given the flag "vector", Q will be returned as a vector such that R' * R = A(Q, Q). Called with either a sparse or full matrix and using the "lower" flag, 'chol' returns the lower triangular factorization such that L * L' = A. For full matrices, if the "lower" flag is set only the lower triangular part of the matrix is used for the factorization, otherwise the upper triangular part is used. In general the lower triangular factorization is significantly faster for sparse matrices. See also: hess, lu, qr, qz, schur, svd, cholinv, chol2inv, cholupdate, cholinsert, choldelete, cholshift. 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:45> b=B*ones(4,1); octave:46> B\b ans = 1.0000 1.0000 1.0000 1.0000 octave:47> R\(R'\b) ans = 1.0000 1.0000 1.0000 1.0000 octave:48> hilb(20) ans = Columns 1 through 6: 1.000000 0.500000 0.333333 0.250000 0.200000 0.166667 0.500000 0.333333 0.250000 0.200000 0.166667 0.142857 0.333333 0.250000 0.200000 0.166667 0.142857 0.125000 0.250000 0.200000 0.166667 0.142857 0.125000 0.111111 0.200000 0.166667 0.142857 0.125000 0.111111 0.100000 0.166667 0.142857 0.125000 0.111111 0.100000 0.090909 0.142857 0.125000 0.111111 0.100000 0.090909 0.083333 0.125000 0.111111 0.100000 0.090909 0.083333 0.076923 0.111111 0.100000 0.090909 0.083333 0.076923 0.071429 0.100000 0.090909 0.083333 0.076923 0.071429 0.066667 0.090909 0.083333 0.076923 0.071429 0.066667 0.062500 0.083333 0.076923 0.071429 0.066667 0.062500 0.058824 0.076923 0.071429 0.066667 0.062500 0.058824 0.055556 0.071429 0.066667 0.062500 0.058824 0.055556 0.052632 0.066667 0.062500 0.058824 0.055556 0.052632 0.050000 0.062500 0.058824 0.055556 0.052632 0.050000 0.047619 0.058824 0.055556 0.052632 0.050000 0.047619 0.045455 0.055556 0.052632 0.050000 0.047619 0.045455 0.043478 0.052632 0.050000 0.047619 0.045455 0.043478 0.041667 0.050000 0.047619 0.045455 0.043478 0.041667 0.040000 Columns 7 through 12: 0.142857 0.125000 0.111111 0.100000 0.090909 0.083333 0.125000 0.111111 0.100000 0.090909 0.083333 0.076923 0.111111 0.100000 0.090909 0.083333 0.076923 0.071429 0.100000 0.090909 0.083333 0.076923 0.071429 0.066667 0.090909 0.083333 0.076923 0.071429 0.066667 0.062500 0.083333 0.076923 0.071429 0.066667 0.062500 0.058824 0.076923 0.071429 0.066667 0.062500 0.058824 0.055556 0.071429 0.066667 0.062500 0.058824 0.055556 0.052632 0.066667 0.062500 0.058824 0.055556 0.052632 0.050000 0.062500 0.058824 0.055556 0.052632 0.050000 0.047619 0.058824 0.055556 0.052632 0.050000 0.047619 0.045455 0.055556 0.052632 0.050000 0.047619 0.045455 0.043478 0.052632 0.050000 0.047619 0.045455 0.043478 0.041667 0.050000 0.047619 0.045455 0.043478 0.041667 0.040000 0.047619 0.045455 0.043478 0.041667 0.040000 0.038462 0.045455 0.043478 0.041667 0.040000 0.038462 0.037037 0.043478 0.041667 0.040000 0.038462 0.037037 0.035714 0.041667 0.040000 0.038462 0.037037 0.035714 0.034483 0.040000 0.038462 0.037037 0.035714 0.034483 0.033333 0.038462 0.037037 0.035714 0.034483 0.033333 0.032258 Columns 13 through 18: 0.076923 0.071429 0.066667 0.062500 0.058824 0.055556 0.071429 0.066667 0.062500 0.058824 0.055556 0.052632 0.066667 0.062500 0.058824 0.055556 0.052632 0.050000 0.062500 0.058824 0.055556 0.052632 0.050000 0.047619 0.058824 0.055556 0.052632 0.050000 0.047619 0.045455 0.055556 0.052632 0.050000 0.047619 0.045455 0.043478 0.052632 0.050000 0.047619 0.045455 0.043478 0.041667 0.050000 0.047619 0.045455 0.043478 0.041667 0.040000 0.047619 0.045455 0.043478 0.041667 0.040000 0.038462 0.045455 0.043478 0.041667 0.040000 0.038462 0.037037 0.043478 0.041667 0.040000 0.038462 0.037037 0.035714 0.041667 0.040000 0.038462 0.037037 0.035714 0.034483 0.040000 0.038462 0.037037 0.035714 0.034483 0.033333 0.038462 0.037037 0.035714 0.034483 0.033333 0.032258 0.037037 0.035714 0.034483 0.033333 0.032258 0.031250 0.035714 0.034483 0.033333 0.032258 0.031250 0.030303 0.034483 0.033333 0.032258 0.031250 0.030303 0.029412 0.033333 0.032258 0.031250 0.030303 0.029412 0.028571 0.032258 0.031250 0.030303 0.029412 0.028571 0.027778 0.031250 0.030303 0.029412 0.028571 0.027778 0.027027 Columns 19 and 20: 0.052632 0.050000 0.050000 0.047619 0.047619 0.045455 0.045455 0.043478 0.043478 0.041667 0.041667 0.040000 0.040000 0.038462 0.038462 0.037037 0.037037 0.035714 0.035714 0.034483 0.034483 0.033333 0.033333 0.032258 0.032258 0.031250 0.031250 0.030303 0.030303 0.029412 0.029412 0.028571 0.028571 0.027778 0.027778 0.027027 0.027027 0.026316 0.026316 0.025641 octave:49> chol(hilb(20)) error: chol: input matrix must be positive definite octave:49> cond(hilb(20)) ans = 2.5703e+18 octave:50> A=sprand(4,4,0.1) A = Compressed Column Sparse (rows = 4, cols = 4, nnz = 2 [12%]) (1, 2) -> 0.45347 (3, 2) -> 0.40435 octave:51> full(A) ans = 0.00000 0.45347 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.40435 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 octave:52> sparse(full(A)) ans = Compressed Column Sparse (rows = 4, cols = 4, nnz = 2 [12%]) (1, 2) -> 0.45347 (3, 2) -> 0.40435 octave:53> A A = Compressed Column Sparse (rows = 4, cols = 4, nnz = 2 [12%]) (1, 2) -> 0.45347 (3, 2) -> 0.40435 octave:54> B=full(A) B = 0.00000 0.45347 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.40435 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 octave:55> whos Variables in the current scope: Attr Name Size Bytes Class ==== ==== ==== ===== ===== A 4x4 44 double B 4x4 128 double L 4x4 128 double P 4x4 16 double R 4x4 128 double U 4x4 128 double ans 4x4 44 double b 4x1 32 double p 4x1 32 double x 4x1 32 double Total is 96 elements using 712 bytes octave:56> diag([1,2,3]) ans = Diagonal Matrix 1 0 0 0 2 0 0 0 3 octave:57> sparse(diag([1,2,3])) ans = Compressed Column Sparse (rows = 3, cols = 3, nnz = 3 [33%]) (1, 1) -> 1 (2, 2) -> 2 (3, 3) -> 3 octave:58> ls 2016-10-05.txt fun~ fun.m~ Jfun.m~ newton.m~ fun fun.m Jfun.m newton.m octave:59> newton(@fun,@Jfun,[1;1],1e-6) error: newton: operator \: nonconformant arguments (op1 is 2x2, op2 is 1x2) error: called from: error: /home/accounts/personale/clrmrc90/aa1617/equazioni_differenziali/newton.m at line 3, column 7 octave:59> newton(@fun,@Jfun,[1;1],1e-6) error: newton: operator \: nonconformant arguments (op1 is 2x2, op2 is 1x2) error: called from: error: /home/accounts/personale/clrmrc90/aa1617/equazioni_differenziali/newton.m at line 3, column 7 octave:59> fun([1;1]) ans = 1 2 octave:60> fun([1;1]) ans = 1 2 octave:61> fun([1;1]) ans = 1 2 octave:62> pwd ans = /home/accounts/personale/clrmrc90/aa1617/equazioni_differenziali octave:63> ls 2016-10-05.txt fun.m Jfun.m newton.m fun~ fun.m~ Jfun.m~ newton.m~ octave:64> Jfun([1;1]) ans = 2.0000e+00 2.0000e+00 9.6184e-17 3.0000e+00 octave:65> fun([1,1]) ans = 1 2 octave:66> fun([1;1]) ans = 1 2 octave:67> fun([1;1]) ans = 1 2 octave:68> fun([1;1]) ans = 1 2 octave:69> clear all octave:70> fun([1;1]) ciao f = 1 2 ans = 1 2 octave:71> fun([1;1]) ciao f = 1 2 ans = 1 2 octave:72> clear all octave:73> fun([1;1]) ans = 1 2 octave:74> newton(@fun,@Jfun,[1;1],1e-6) ans = 0.47610 -0.87939 octave:75> x=newton(@fun,@Jfun,[1;1],1e-6) x = 0.47610 -0.87939 octave:76> fun(x) ans = 8.7594e-12 -2.0567e-11 octave:77> x=newton(@fun,@Jfun,[1;1],1e-6) ans = 2.4144 ans = 1.1626 ans = 0.45504 ans = 0.20920 ans = 0.042336 ans = 0.0015990 ans = 2.7104e-06 ans = 7.0069e-12 x = 0.47610 -0.87939 octave:78> x=newton(@fun,@Jfun,[1;1],1e-6) ans = 2.5912 ans = 1.1882 ans = 0.46950 ans = 0.37695 ans = 0.10931 ans = 0.017807 ans = 0.0037146 ans = 7.7675e-04 ans = 1.6358e-04 ans = 3.4406e-05 ans = 7.2386e-06 ans = 1.5228e-06 ans = 3.2037e-07 x = 0.47610 -0.87939 octave:79> newton_script error: 'newton_script' undefined near line 1 column 1 octave:79> ls 2016-10-05.txt fun.m Jfun.m newton.m newton_script.m fun~ fun.m~ Jfun.m~ newton.m~ newton_script.m~ octave:80> ls 2016-10-05.txt fun.m~ newton.m newton_script.m~ fun~ Jfun.m newton.m~ newtonscript.m fun.m Jfun.m~ newton_script.m octave:81> newtonscript error: 'tol' undefined near line 9 column 26 error: called from: error: /home/accounts/personale/clrmrc90/aa1617/equazioni_differenziali/newtonscript.m at line 9, column 1 octave:81> newtonscript x = 0.47610 -0.87939 octave:82> diary off