octave:2> H=hilb(15); octave:3> b=rand(15,1); octave:4> H\b warning: matrix singular to machine precision, rcond = 1.5434e-18 ans = 6.3678e+06 -6.9461e+08 1.8496e+10 -2.0683e+11 1.1793e+12 -3.6599e+12 5.8851e+12 -3.1331e+12 -3.3623e+12 3.4133e+12 3.1932e+12 -3.1415e+12 -3.5524e+12 4.9241e+12 -1.5567e+12 octave:5> x=H\b x = 6.3678e+06 -6.9461e+08 1.8496e+10 -2.0683e+11 1.1793e+12 -3.6599e+12 5.8851e+12 -3.1331e+12 -3.3623e+12 3.4133e+12 3.1932e+12 -3.1415e+12 -3.5524e+12 4.9241e+12 -1.5567e+12 octave:6> norm(H*x-b) ans = 0.82592 octave:7> H*x-b ans = -1.1460e-03 -2.8304e-04 -5.2835e-04 3.2036e-03 -2.6334e-02 1.1356e-01 -2.9244e-01 4.1879e-01 -2.2143e-01 -2.1203e-01 3.1429e-01 7.5370e-02 -3.7218e-01 2.5886e-01 -6.0450e-02 octave:8> v=randn(5,1) v = -0.12520 0.23531 -0.32537 0.54519 -0.95258 octave:9> max(abs(v)) ans = 0.95258 octave:10> [m,idx]=max(abs(v)) m = 0.95258 idx = 5 octave:11> [~,idx]=max(abs(v)) idx = 5 octave:12> [max,idx]=max(abs(v)) max = 0.95258 idx = 5 octave:13> max(abs(v)) error: subscript indices must be either positive integers less than 2^31 or logicals octave:13> [max,idx]=max(abs(v)) error: subscript indices must be either positive integers less than 2^31 or logicals octave:13> clear max octave:14> max([1,2]) ans = 2 octave:15> [~,idx]=max(abs(v)) idx = 5 octave:16> [~,idx]=max(abs(v(3:5))) idx = 3 octave:17> v(3:5) ans = -0.32537 0.54519 -0.95258 octave:18> ls 20190311.txt 20190408.txt bisezione.m~ figtree.txt miafunzione.m~ polinomio0.m~ primoscript.m 2019-03-18.txt 20190429.txt bs.m horner.m newton.m polinomio1.m radice.m 2019-03-25.txt bintodec.m bs.m~ megp0.m newton.m~ polinomio1.m~ 20190401.txt bisezione.m dectobin.m miafunzione.m polinomio0.m primafunction.m octave:19> A=randn(4); octave:20> b=randn(4,1); octave:21> [x,U,bhat]=megp0(A,b) x = -7.5130 2.2438 2.2643 11.2042 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 bhat = 0.82883 0.66238 -0.57646 -0.62544 octave:22> A\b ans = -7.5130 2.2438 2.2643 11.2042 octave:23> x x = -7.5130 2.2438 2.2643 11.2042 octave:24> U U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 octave:25> bhat bhat = 0.82883 0.66238 -0.57646 -0.62544 octave:26> U\bhat ans = -7.5130 2.2438 2.2643 11.2042 octave:27> x x = -7.5130 2.2438 2.2643 11.2042 octave:28> 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:29> [L,U]=lu(A) L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 octave:30> A A = -0.610670 0.453375 0.490647 -0.636585 -1.666947 1.007433 0.516499 -1.349927 0.960570 0.015549 2.053672 0.119131 -0.815947 -2.268710 0.734912 -0.145980 octave:31> L*U ans = -0.610670 0.453375 0.490647 -0.636585 -1.666947 1.007433 0.516499 -1.349927 0.960570 0.015549 2.053672 0.119131 -0.815947 -2.268710 0.734912 -0.145980 octave:32> [L,U,P]=lu(A) L = 1.00000 0.00000 0.00000 0.00000 0.48949 1.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.36634 -0.03053 0.12876 1.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 P = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:33> P*A ans = -1.666947 1.007433 0.516499 -1.349927 -0.815947 -2.268710 0.734912 -0.145980 0.960570 0.015549 2.053672 0.119131 -0.610670 0.453375 0.490647 -0.636585 octave:34> L*U ans = -1.666947 1.007433 0.516499 -1.349927 -0.815947 -2.268710 0.734912 -0.145980 0.960570 0.015549 2.053672 0.119131 -0.610670 0.453375 0.490647 -0.636585 octave:35> b b = -0.41625 0.82883 -1.19703 1.06808 octave:36> y=L\(P*b); octave:37> x=U\y x = -7.5130 2.2438 2.2643 11.2042 octave:38> x=U\(L\(P*b)) x = -7.5130 2.2438 2.2643 11.2042 octave:39> [L,U]=lu(A); octave:40> L L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 octave:41> [L,U,P]=lu(A); octave:42> P\L ans = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 octave:43> P P = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:44> v=[1;2;3;4] v = 1 2 3 4 octave:45> P*v ans = 2 4 3 1 octave:46> A A = -0.610670 0.453375 0.490647 -0.636585 -1.666947 1.007433 0.516499 -1.349927 0.960570 0.015549 2.053672 0.119131 -0.815947 -2.268710 0.734912 -0.145980 octave:47> diag(A) ans = -0.61067 1.00743 2.05367 -0.14598 octave:48> diag([1,2,3,4]) ans = Diagonal Matrix 1 0 0 0 0 2 0 0 0 0 3 0 0 0 0 4 octave:49> diag(diag(A)) ans = Diagonal Matrix -0.61067 0 0 0 0 1.00743 0 0 0 0 2.05367 0 0 0 0 -0.14598 octave:50> A A = -0.610670 0.453375 0.490647 -0.636585 -1.666947 1.007433 0.516499 -1.349927 0.960570 0.015549 2.053672 0.119131 -0.815947 -2.268710 0.734912 -0.145980 octave:51> eye(4) ans = Diagonal Matrix 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 octave:52> I=eye(4) I = Diagonal Matrix 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 octave:53> p=[2;4;3;1] p = 2 4 3 1 octave:54> I(p,:) ans = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:55> I I = Diagonal Matrix 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 octave:56> I([2,3],:) ans = 0 1 0 0 0 0 1 0 octave:57> I([3,2],:) ans = 0 0 1 0 0 1 0 0 octave:58> I(p,:) ans = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:59> p p = 2 4 3 1 octave:60> L L = 1.00000 0.00000 0.00000 0.00000 0.48949 1.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.36634 -0.03053 0.12876 1.00000 octave:61> [L,U,P]=lu(A) L = 1.00000 0.00000 0.00000 0.00000 0.48949 1.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.36634 -0.03053 0.12876 1.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 P = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:62> [L,U,P]=lup0_kij(A) L = 1.00000 0.00000 0.00000 0.00000 0.48949 1.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.36634 -0.03053 0.12876 1.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 P = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:63> [L,U]=lu(A) L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 octave:64> p=[2;4;3;1] p = 2 4 3 1 octave:65> L(p,:)=L L = 0.48949 1.00000 0.00000 0.00000 0.36634 -0.03053 0.12876 1.00000 -0.57625 -0.21583 1.00000 0.00000 1.00000 0.00000 0.00000 0.00000 octave:66> [L,U]=lu(A) L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 octave:67> [L,U]=lup0_kij(A) L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 octave:68> [L,U]=lup0_kij(A) p = 2 4 3 1 L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 octave:69> p=[2,4,3,1] p = 2 4 3 1 octave:70> [L,U,P]=lu(A) L = 1.00000 0.00000 0.00000 0.00000 0.48949 1.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.36634 -0.03053 0.12876 1.00000 U = -1.66695 1.00743 0.51650 -1.34993 0.00000 -2.76183 0.48209 0.51479 0.00000 0.00000 2.45535 -0.54765 0.00000 0.00000 0.00000 -0.05582 P = Permutation Matrix 0 1 0 0 0 0 0 1 0 0 1 0 1 0 0 0 octave:71> L(p,:)=L L = 0.36634 -0.03053 0.12876 1.00000 1.00000 0.00000 0.00000 0.00000 -0.57625 -0.21583 1.00000 0.00000 0.48949 1.00000 0.00000 0.00000 octave:72> help roots 'roots' is a function from the file /usr/share/octave/3.8.1/m/polynomial/roots.m -- Function File: roots (V) For a vector V with N components, return the roots of the polynomial v(1) * z^(N-1) + ... + v(N-1) * z + v(N) As an example, the following code finds the roots of the quadratic polynomial p(x) = x^2 - 5. c = [1, 0, -5]; roots (c) => 2.2361 => -2.2361 Note that the true result is +/- sqrt(5) which is roughly +/- 2.2361. See also: poly, compan, fzero. 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:73> roots([1,-3,2]) ans = 2 1 octave:74> x=linspace(0,10) x = Columns 1 through 11: 0.00000 0.10101 0.20202 0.30303 0.40404 0.50505 0.60606 0.70707 0.80808 0.90909 1.01010 Columns 12 through 22: 1.11111 1.21212 1.31313 1.41414 1.51515 1.61616 1.71717 1.81818 1.91919 2.02020 2.12121 Columns 23 through 33: 2.22222 2.32323 2.42424 2.52525 2.62626 2.72727 2.82828 2.92929 3.03030 3.13131 3.23232 Columns 34 through 44: 3.33333 3.43434 3.53535 3.63636 3.73737 3.83838 3.93939 4.04040 4.14141 4.24242 4.34343 Columns 45 through 55: 4.44444 4.54545 4.64646 4.74747 4.84848 4.94949 5.05051 5.15152 5.25253 5.35354 5.45455 Columns 56 through 66: 5.55556 5.65657 5.75758 5.85859 5.95960 6.06061 6.16162 6.26263 6.36364 6.46465 6.56566 Columns 67 through 77: 6.66667 6.76768 6.86869 6.96970 7.07071 7.17172 7.27273 7.37374 7.47475 7.57576 7.67677 Columns 78 through 88: 7.77778 7.87879 7.97980 8.08081 8.18182 8.28283 8.38384 8.48485 8.58586 8.68687 8.78788 Columns 89 through 99: 8.88889 8.98990 9.09091 9.19192 9.29293 9.39394 9.49495 9.59596 9.69697 9.79798 9.89899 Column 100: 10.00000 octave:75> x=linspace(0,10,101) x = Columns 1 through 11: 0.00000 0.10000 0.20000 0.30000 0.40000 0.50000 0.60000 0.70000 0.80000 0.90000 1.00000 Columns 12 through 22: 1.10000 1.20000 1.30000 1.40000 1.50000 1.60000 1.70000 1.80000 1.90000 2.00000 2.10000 Columns 23 through 33: 2.20000 2.30000 2.40000 2.50000 2.60000 2.70000 2.80000 2.90000 3.00000 3.10000 3.20000 Columns 34 through 44: 3.30000 3.40000 3.50000 3.60000 3.70000 3.80000 3.90000 4.00000 4.10000 4.20000 4.30000 Columns 45 through 55: 4.40000 4.50000 4.60000 4.70000 4.80000 4.90000 5.00000 5.10000 5.20000 5.30000 5.40000 Columns 56 through 66: 5.50000 5.60000 5.70000 5.80000 5.90000 6.00000 6.10000 6.20000 6.30000 6.40000 6.50000 Columns 67 through 77: 6.60000 6.70000 6.80000 6.90000 7.00000 7.10000 7.20000 7.30000 7.40000 7.50000 7.60000 Columns 78 through 88: 7.70000 7.80000 7.90000 8.00000 8.10000 8.20000 8.30000 8.40000 8.50000 8.60000 8.70000 Columns 89 through 99: 8.80000 8.90000 9.00000 9.10000 9.20000 9.30000 9.40000 9.50000 9.60000 9.70000 9.80000 Columns 100 and 101: 9.90000 10.00000 octave:76> x=linspace(0,10,101); octave:77> f=@(x) x.^2-sin(pi*x).*exp(-x); octave:78> plot(x,f(x)) octave:79> octave:79> x=linspace(0,1,101); octave:80> plot(x,f(x)) octave:81> g=@(x) sin(pi*x).*exp(-x)./x; octave:82> x=0.7 x = 0.70000 octave:83> x=g(x) x = 0.57392 octave:84> x=g(x) x = 0.95516 octave:85> x=g(x) x = 0.056554 octave:86> x=g(x) x = 2.9533 octave:87> x=g(x) x = 0.0025847 octave:88> x=g(x) x = 3.1334 octave:89> x=g(x) x = -0.0056598 octave:90> x=g(x) x = 3.1593 octave:91> g=@(x) -log(x.^2./sin(pi*x)); octave:92> x=0.7 x = 0.70000 octave:93> x=g(x) x = 0.50141 octave:94> x=g(x) x = 1.3806 octave:95> x=g(x) x = -0.71711 - 3.14159i octave:96> log(-1) ans = 0.00000 + 3.14159i octave:97> sqrt(-1) ans = 0 + 1i octave:98> g=@(x) sqrt(sin(pi*x).*exp(-x)); octave:99> x=0.7 x = 0.70000 octave:100> x=g(x) x = 0.63383 octave:101> x=g(x) x = 0.69595 octave:102> x=g(x) x = 0.63802 octave:103> x=g(x) x = 0.69242 octave:104> x=g(x) x = 0.64164 octave:105> x=g(x) x = 0.68933 octave:106> x=g(x) x = 0.64476 octave:107> x=g(x) x = 0.68662 octave:108> x=g(x) x = 0.64748 octave:109> x=g(x) x = 0.68424 octave:110> x=g(x) x = 0.64985 octave:111> x=g(x) x = 0.68215 octave:112> x=g(x) x = 0.65191 octave:113> x=g(x) x = 0.68031 octave:114> x=g(x) x = 0.65372 octave:115> x=g(x) x = 0.67870 octave:116> x=g(x) x = 0.65530 octave:117> x=g(x) x = 0.67727 octave:118> x=g(x) x = 0.65669 octave:119> x=g(x) x = 0.67602 octave:120> x=g(x) x = 0.65790 octave:121> octave:121> x=g(x) x = 0.67491 octave:122> x=g(x) x = 0.65897 octave:123> x=g(x) x = 0.67394 octave:124> x=g(x) x = 0.65990 octave:125> x=g(x) x = 0.67308 octave:126> x=g(x) x = 0.66073 octave:127> x=g(x) x = 0.67233 octave:128> x=g(x) x = 0.66145 octave:129> x=g(x) x = 0.67166 octave:130> x=g(x) x = 0.66208 octave:131> x=g(x) x = 0.67107 octave:132> x=g(x) x = 0.66264 octave:133> x=g(x) x = 0.67056 octave:134> x=g(x) x = 0.66313 octave:135> x=g(x) x = 0.67010 octave:136> x=g(x) x = 0.66357 octave:137> x=g(x) x = 0.66970 octave:138> quit