octave:2> P=catenanm(10) P = Columns 1 through 7: 0.27435 0.72565 0.00000 0.00000 0.00000 0.00000 0.00000 0.25719 0.24122 0.50160 0.00000 0.00000 0.00000 0.00000 0.00000 0.21086 0.36784 0.42130 0.00000 0.00000 0.00000 0.00000 0.00000 0.33588 0.18766 0.47646 0.00000 0.00000 0.00000 0.00000 0.00000 0.48935 0.17352 0.33713 0.00000 0.00000 0.00000 0.00000 0.00000 0.18349 0.15881 0.65770 0.00000 0.00000 0.00000 0.00000 0.00000 0.00425 0.29129 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.48272 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 Columns 8 through 10: 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.70445 0.00000 0.00000 0.25356 0.26372 0.00000 0.48819 0.21359 0.29822 0.00000 0.53824 0.46176 octave:3> isstoc(P) ans = 1 octave:4> v=invariantPotenze(P,1e-6,100) warning: Impossibile raggiungere la tolleranza richiesta warning: entro il numero massimo di iterazioni consentito. v = Columns 1 through 5: 2.4781e-04 6.7224e-04 1.4802e-03 1.6721e-03 1.4265e-03 Columns 6 through 10: 1.9474e-03 2.6956e-01 3.9315e-01 2.1227e-01 1.1757e-01 octave:5> v=invariantPotenze(P,1e-6,200) warning: Impossibile raggiungere la tolleranza richiesta warning: entro il numero massimo di iterazioni consentito. v = Columns 1 through 5: 1.1664e-04 3.2897e-04 7.8196e-04 9.7991e-04 9.5308e-04 Columns 6 through 10: 1.7478e-03 2.7008e-01 3.9413e-01 2.1291e-01 1.1797e-01 octave:6> v=invariantVD(P) v = Columns 1 through 5: 1.1598e-04 3.2724e-04 7.7844e-04 9.7641e-04 9.5069e-04 Columns 6 through 10: 1.7467e-03 2.7008e-01 3.9414e-01 2.1291e-01 1.1797e-01 octave:7> v=invariantPotenze(P,1e-6,300) v = Columns 1 through 5: 1.1644e-04 3.2845e-04 7.8091e-04 9.7887e-04 9.5237e-04 Columns 6 through 10: 1.7475e-03 2.7008e-01 3.9414e-01 2.1291e-01 1.1797e-01 octave:8> p=diag(P,1) p = 0.72565 0.50160 0.42130 0.47646 0.33713 0.65770 0.70445 0.26372 0.29822 octave:9> q=diag(P,-1) q = 0.2571854 0.2108596 0.3358805 0.4893498 0.1834895 0.0042537 0.4827231 0.4881905 0.5382418 octave:10> xi(1)=1 xi = 1 octave:11> for i=1:9 > xi(i+1)=xi(i)*p(i)/q(i); > end octave:12> xi xi = Columns 1 through 6: 1.0000 2.8215 6.7119 8.4188 8.1970 15.0608 Columns 7 through 10: 2328.6967 3398.3381 1835.7796 1017.1460 octave:13> v v = Columns 1 through 5: 1.1644e-04 3.2845e-04 7.8091e-04 9.7887e-04 9.5237e-04 Columns 6 through 10: 1.7475e-03 2.7008e-01 3.9414e-01 2.1291e-01 1.1797e-01 octave:14> v/v(1) ans = Columns 1 through 6: 1.0000 2.8207 6.7063 8.4063 8.1787 15.0068 Columns 7 through 10: 2319.3901 3384.7500 1828.4359 1013.0760 octave:15> xi xi = Columns 1 through 6: 1.0000 2.8215 6.7119 8.4188 8.1970 15.0608 Columns 7 through 10: 2328.6967 3398.3381 1835.7796 1017.1460 octave:16> v=invariantVD(P) v = Columns 1 through 5: 1.1598e-04 3.2724e-04 7.7844e-04 9.7641e-04 9.5069e-04 Columns 6 through 10: 1.7467e-03 2.7008e-01 3.9414e-01 2.1291e-01 1.1797e-01 octave:17> v/v(1) ans = Columns 1 through 6: 1.0000 2.8215 6.7119 8.4188 8.1970 15.0608 Columns 7 through 10: 2328.6967 3398.3381 1835.7796 1017.1460 octave:18> xi xi = Columns 1 through 6: 1.0000 2.8215 6.7119 8.4188 8.1970 15.0608 Columns 7 through 10: 2328.6967 3398.3381 1835.7796 1017.1460 octave:19> v=[1,2,3,4] v = 1 2 3 4 octave:20> cumprod(v) ans = 1 2 6 24 octave:21> [1;cumprod(p./q)]' ans = Columns 1 through 6: 1.0000 2.8215 6.7119 8.4188 8.1970 15.0608 Columns 7 through 10: 2328.6967 3398.3381 1835.7796 1017.1460 octave:22> xi xi = Columns 1 through 6: 1.0000 2.8215 6.7119 8.4188 8.1970 15.0608 Columns 7 through 10: 2328.6967 3398.3381 1835.7796 1017.1460 octave:23> tic,invariantPotenze(P,1e-6,300);,toc Elapsed time is 0.03439 seconds. octave:24> tic,invariantPotenze(P,1e-6,300);,toc Elapsed time is 0.0276 seconds. octave:25> tic,invariantPotenze(P,1e-6,300);,toc Elapsed time is 0.02365 seconds. octave:26> tic,invariantPotenze(P,1e-6,300);,toc Elapsed time is 0.03306 seconds. octave:27> Psparse=sparse(P),tic,invariantPotenze(Psparse,1e-6,300);,toc Psparse = Compressed Column Sparse (rows = 10, cols = 10, nnz = 28) (1, 1) -> 0.27435 (2, 1) -> 0.25719 (1, 2) -> 0.72565 (2, 2) -> 0.24122 (3, 2) -> 0.21086 (2, 3) -> 0.50160 (3, 3) -> 0.36784 (4, 3) -> 0.33588 (3, 4) -> 0.42130 (4, 4) -> 0.18766 (5, 4) -> 0.48935 (4, 5) -> 0.47646 (5, 5) -> 0.17352 (6, 5) -> 0.18349 (5, 6) -> 0.33713 (6, 6) -> 0.15881 (7, 6) -> 0.0042537 (6, 7) -> 0.65770 (7, 7) -> 0.29129 (8, 7) -> 0.48272 (7, 8) -> 0.70445 (8, 8) -> 0.25356 (9, 8) -> 0.48819 (8, 9) -> 0.26372 (9, 9) -> 0.21359 (10, 9) -> 0.53824 (9, 10) -> 0.29822 (10, 10) -> 0.46176 Elapsed time is 0.036313 seconds. octave:28> Psparse=sparse(P);,tic,invariantPotenze(Psparse,1e-6,300);,toc Elapsed time is 0.022606 seconds. octave:29> Psparse=sparse(P);,tic,invariantPotenze(Psparse,1e-6,300);,toc Elapsed time is 0.022312 seconds. octave:30> Psparse=sparse(P);,tic,invariantPotenze(Psparse,1e-6,300);,toc Elapsed time is 0.022318 seconds. octave:31> Psparse=sparse(P);,tic,invariantPotenze(Psparse,1e-6,300);,toc Elapsed time is 0.022364 seconds. octave:32> Psparse=sparse(P);,tic,invariantPotenze(Psparse,1e-6,300);,toc Elapsed time is 0.022403 seconds. octave:33> Psparse=sparse(P);,tic,invariantPotenze(Psparse,1e-6,300);,toc Elapsed time is 0.023839 seconds. octave:34> P P = Columns 1 through 7: 0.27435 0.72565 0.00000 0.00000 0.00000 0.00000 0.00000 0.25719 0.24122 0.50160 0.00000 0.00000 0.00000 0.00000 0.00000 0.21086 0.36784 0.42130 0.00000 0.00000 0.00000 0.00000 0.00000 0.33588 0.18766 0.47646 0.00000 0.00000 0.00000 0.00000 0.00000 0.48935 0.17352 0.33713 0.00000 0.00000 0.00000 0.00000 0.00000 0.18349 0.15881 0.65770 0.00000 0.00000 0.00000 0.00000 0.00000 0.00425 0.29129 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.48272 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 Columns 8 through 10: 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.70445 0.00000 0.00000 0.25356 0.26372 0.00000 0.48819 0.21359 0.29822 0.00000 0.53824 0.46176 octave:35> P=catenanm(4) P = 0.07881 0.92119 0.00000 0.00000 0.12221 0.04323 0.83457 0.00000 0.00000 0.31779 0.42053 0.26168 0.00000 0.00000 0.97972 0.02028 octave:36> S=catenanm(4) S = 0.16259 0.83741 0.00000 0.00000 0.49729 0.08459 0.41813 0.00000 0.00000 0.46888 0.09993 0.43118 0.00000 0.00000 0.90375 0.09625 octave:37> [Q,R,P]=qr(S'-eye(4)); octave:38> Q*R*P' ans = -0.83741 0.49729 -0.00000 0.00000 0.83741 -0.91541 0.46888 0.00000 -0.00000 0.41813 -0.90007 0.90375 0.00000 -0.00000 0.43118 -0.90375 octave:39> S'-eye(4) ans = -0.83741 0.49729 0.00000 0.00000 0.83741 -0.91541 0.46888 0.00000 0.00000 0.41813 -0.90007 0.90375 0.00000 0.00000 0.43118 -0.90375 octave:40> R R = -1.27809 0.00000 0.94134 -0.29566 0.00000 -1.18428 -0.33155 0.99893 0.00000 0.00000 0.46888 -0.41813 0.00000 0.00000 0.00000 0.00000 octave:41> v=[1,2,3]/6 v = 0.16667 0.33333 0.50000 octave:42> V=repmat(v,3,1) V = 0.16667 0.33333 0.50000 0.16667 0.33333 0.50000 0.16667 0.33333 0.50000 octave:43> W=repmat(v',1,3) W = 0.16667 0.16667 0.16667 0.33333 0.33333 0.33333 0.50000 0.50000 0.50000 octave:44> V>=W ans = 1 1 1 0 1 1 0 0 1 octave:45> find(V>=W) ans = 1 4 5 7 8 9 octave:46> pwd ans = /home/accounts/altri/caliari/aa0910/sistemi_stocastici/algebra octave:47> cd .. octave:48> cd metropolis/ octave:49> v v = 0.16667 0.33333 0.50000 octave:50> P=metropolis(v,eye(3)) P = 1 0 0 0 1 0 0 0 1 octave:51> P=metropolis(v,stocsym(3)) P = 0.457867 0.123904 0.418229 0.061952 0.405693 0.532355 0.139410 0.354903 0.505687 octave:52> P=metropolis(v,stocsym(3)) P = 0.36637 0.30348 0.33015 0.15174 0.58862 0.25964 0.11005 0.17309 0.71686 octave:53> P=metropolis(v,stocsym(3)) P = 0.34064 0.28970 0.36965 0.14485 0.51377 0.34138 0.12322 0.22759 0.64920 octave:54> cd .. octave:55> cd algebra/ octave:56> invariantPotenze(P,1e-6,10) warning: Impossibile raggiungere la tolleranza richiesta warning: entro il numero massimo di iterazioni consentito. ans = 0.16667 0.33333 0.50000 octave:57> ls octave:58> stocsym(10) ans = Columns 1 through 6: 0.1017780 0.0675305 0.1007090 0.0033107 0.1309478 0.0121165 0.0675305 0.1591864 0.1679759 0.1291605 0.0126109 0.1744923 0.1007090 0.1679759 0.0096966 0.0962307 0.0488165 0.1362615 0.0033107 0.1291605 0.0962307 0.0194033 0.1517203 0.0596301 0.1309478 0.0126109 0.0488165 0.1517203 0.0896401 0.2249988 0.0121165 0.1744923 0.1362615 0.0596301 0.2249988 0.1092202 0.0922141 0.1062117 0.1369548 0.1469207 0.0724629 0.0786207 0.0620163 0.0348788 0.1003336 0.1790810 0.1775947 0.1138518 0.2024023 0.1083005 0.0608385 0.1643204 0.0254881 0.0657315 0.2269748 0.0396525 0.1421830 0.0502224 0.0657199 0.0250766 Columns 7 through 10: 0.0922141 0.0620163 0.2024023 0.2269748 0.1062117 0.0348788 0.1083005 0.0396525 0.1369548 0.1003336 0.0608385 0.1421830 0.1469207 0.1790810 0.1643204 0.0502224 0.0724629 0.1775947 0.0254881 0.0657199 0.0786207 0.1138518 0.0657315 0.0250766 0.2651448 0.0809970 0.0168684 0.0036049 0.0809970 0.0992921 0.0597082 0.0922465 0.0168684 0.0597082 0.1092025 0.1871395 0.0036049 0.0922465 0.1871395 0.1671799 octave:59> isstoc(stocsym(10)) ans = 1 octave:60> isstoc(stocsym(10)) ans = 1 octave:61> isstoc(stocsym(10)) ans = 1 octave:62> isstoc(stocsym(10)) ans = 1 octave:63> isstoc(stocsym(10)) ans = 1 octave:64> isstoc(stocsym(10)) ans = 1 octave:65> isstoc(stocsym(10)) ans = 1 octave:66> ls octave:67> cd .. octave:68> cd algebra/ octave:69> Q=stocsym(3) Q = 0.24810 0.37927 0.37263 0.37927 0.36459 0.25614 0.37263 0.25614 0.37123 octave:70> cd .. octave:71> cd metropolis/ octave:72> v v = 0.16667 0.33333 0.50000 octave:73> P=metropolis(v,Q) P = 0.24810 0.37927 0.37263 0.18964 0.55423 0.25614 0.12421 0.17076 0.70503 octave:74> cd .. octave:75> cd algebra/ octave:76> invariantPotenze(P,1e-6,100) ans = 0.16667 0.33333 0.50000 octave:77> ls octave:78> cd .. octave:79> cd metropolis/ octave:80> ls octave:81> epsilonmetropolis epsilon = 10 ans = Columns 1 through 5: 3.5655e-01 7.8148e-02 3.8370e-02 7.9649e-02 1.0206e-01 1.0002e-01 2.4428e-01 5.0258e-02 1.0124e-01 1.1113e-01 9.7457e-02 9.9739e-02 1.5963e-01 1.2029e-01 8.8304e-02 1.0194e-01 1.0124e-01 6.0611e-02 2.3292e-01 1.0220e-01 3.4086e-02 2.9001e-02 1.1612e-02 2.6671e-02 7.1607e-01 1.0075e-01 8.6841e-02 5.0382e-02 9.2855e-02 8.6320e-02 9.6169e-02 9.2211e-02 9.3533e-02 9.5864e-02 9.2360e-02 1.0422e-01 9.0502e-02 4.5365e-02 1.0311e-01 1.0299e-01 4.4361e-03 3.4630e-03 1.9398e-03 3.2358e-03 1.4374e-02 1.0406e-01 1.1019e-01 5.9576e-02 1.0546e-01 1.0370e-01 Columns 6 through 10: 7.8721e-02 8.1556e-03 8.1433e-02 9.5613e-02 8.1307e-02 8.6841e-02 1.0008e-02 9.0502e-02 9.5529e-02 1.1019e-01 9.9986e-02 2.0147e-02 9.0028e-02 1.0619e-01 1.1823e-01 9.2855e-02 1.0405e-02 1.0311e-01 8.9260e-02 1.0546e-01 2.2527e-02 2.6161e-03 2.6876e-02 1.0348e-01 2.7063e-02 2.6344e-01 1.3454e-02 8.9457e-02 9.6158e-02 1.2034e-01 1.2396e-01 9.8202e-02 1.0229e-01 1.0743e-01 9.7979e-02 8.9457e-02 1.1102e-02 2.4350e-01 9.9777e-02 1.0998e-01 3.4858e-03 4.2270e-04 3.6170e-03 9.6185e-01 3.1731e-03 1.2034e-01 1.0634e-02 1.0998e-01 8.7531e-02 1.8853e-01 guarda P(5,5) e P(9,9) epsilon = 0.10000 ans = Columns 1 through 5: 8.0233e-01 1.9244e-12 3.2133e-42 1.9613e-12 1.0206e-01 1.0002e-01 3.0455e-01 1.7092e-31 1.0124e-01 1.1113e-01 9.7457e-02 9.9739e-02 1.7978e-01 1.2029e-01 8.8304e-02 1.0194e-01 1.0124e-01 2.0613e-31 3.0394e-01 1.0220e-01 2.4161e-49 5.0620e-60 6.8929e-90 4.6553e-60 8.9652e-01 1.0075e-01 8.6841e-02 1.7134e-31 9.2855e-02 8.6320e-02 9.6169e-02 9.2211e-02 9.3533e-02 9.5864e-02 9.2360e-02 1.0422e-01 9.0502e-02 1.5428e-31 1.0311e-01 1.0299e-01 4.2511e-135 8.1721e-146 1.5567e-175 7.6359e-146 1.9433e-87 1.0406e-01 1.1019e-01 2.0261e-31 1.0546e-01 1.0370e-01 Columns 6 through 10: 1.9385e-12 6.6860e-109 2.0053e-12 9.5613e-02 2.0022e-12 8.6841e-02 3.3320e-98 9.0502e-02 9.5529e-02 1.1019e-01 9.9986e-02 1.9722e-68 9.0028e-02 1.0619e-01 1.1823e-01 9.2855e-02 3.4640e-98 1.0311e-01 8.9260e-02 1.0546e-01 3.9319e-60 1.5202e-156 4.6912e-60 1.0348e-01 4.7238e-60 3.2728e-01 4.4791e-98 8.9457e-02 9.6158e-02 1.2034e-01 1.2396e-01 9.8202e-02 1.0229e-01 1.0743e-01 9.7979e-02 8.9457e-02 3.6962e-98 2.9997e-01 9.9777e-02 1.0998e-01 8.2259e-146 3.3209e-242 8.5355e-146 1.0000e+00 7.4880e-146 1.2034e-01 3.5404e-98 1.0998e-01 8.7531e-02 2.5874e-01 guarda P(5,5) e P(9,9) epsilon = 0.010000 ans = Columns 1 through 7: 0.80233 0.00000 0.00000 0.00000 0.10206 0.00000 0.00000 0.10002 0.30455 0.00000 0.10124 0.11113 0.08684 0.00000 0.09746 0.09974 0.17978 0.12029 0.08830 0.09999 0.00000 0.10194 0.10124 0.00000 0.30394 0.10220 0.09285 0.00000 0.00000 0.00000 0.00000 0.00000 0.89652 0.00000 0.00000 0.10075 0.08684 0.00000 0.09285 0.08632 0.32728 0.00000 0.09617 0.09221 0.09353 0.09586 0.09236 0.12396 0.09820 0.10422 0.09050 0.00000 0.10311 0.10299 0.08946 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000 0.10406 0.11019 0.00000 0.10546 0.10370 0.12034 0.00000 Columns 8 through 10: 0.00000 0.09561 0.00000 0.09050 0.09553 0.11019 0.09003 0.10619 0.11823 0.10311 0.08926 0.10546 0.00000 0.10348 0.00000 0.08946 0.09616 0.12034 0.10229 0.10743 0.09798 0.29997 0.09978 0.10998 0.00000 1.00000 0.00000 0.10998 0.08753 0.25874 guarda P(5,5) e P(9,9) octave:82> diary off