v=rand(1,3);
v=v/sum(v);
v
v =
0.4410 0.4903 0.0687
cumsum(v)
ans =
0.4410 0.9313 1.0000
rand
ans =
0.9134
rand
ans =
0.6324
rand
ans =
0.0975
find(rand < cumsum(v))
ans =
1 2 3
find(rand < cumsum(v),1)
ans =
2
find(rand < cumsum(v),1)
ans =
3
find(rand < cumsum(v),1)
ans =
3
find(rand < cumsum(v),1)
ans =
1
find(rand < cumsum(v),1)
ans =
3
find(rand < cumsum(v),1)
ans =
3
find(rand < cumsum(v),1)
ans =
2
find(rand < cumsum(v),1)
ans =
2
find(rand < cumsum(v),1)
ans =
1
v
v =
0.4410 0.4903 0.0687
edit
randdisc([0.5,0.5])
ans =
1
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
1
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
randdisc([0.5,0.5])
ans =
2
edit
cd ..
cd sistemi_stocastici/
ls
2012-10-26.txt metropolis.m~
2012-11-09.txt metropolisminimo.m
epsmet.m randstoc.m
invariantPotenze.m randstocsym.m
metropolis.m
P=randstoc(4);
simula(P,1,1)
ans =
3
simula(P,10,1)
ans =
1
% Modify expression to add input arguments.
% Example:
% a = [1 2 3; 4 5 6];
% foo(a);
testsimula
??? Undefined function or method 'catenanm' for
input arguments of type 'double'.
Error in ==> testsimula at 5
P = catenanm(n);
testsimula
for j=1:10
j
end
j =
1
j =
2
j =
3
j =
4
j =
5
j =
6
j =
7
j =
8
j =
9
j =
10
for j=1:10
j=j+5
end
j =
6
j =
7
j =
8
j =
9
j =
10
j =
11
j =
12
j =
13
j =
14
j =
15
% Modify expression to add input arguments.
% Example:
% a = [1 2 3; 4 5 6];
% foo(a);
testsimula
H(100,39)
ans =
-7.4796
H(100,38)
ans =
-6.0023
H(100,[1,2])
ans =
-2.4674 -2.5925
H(100,1:100)
ans =
Columns 1 through 4
-2.4674 -2.5925 -2.6631 -2.6711
Columns 5 through 8
-2.6094 -2.4726 -2.2568 -1.9599
Columns 9 through 12
-1.5822 -1.1260 -0.5962 -0.0000
Columns 13 through 16
0.6530 1.3507 2.0792 2.8223
Columns 17 through 20
3.5625 4.2808 4.9577 5.5729
Columns 21 through 24
6.1067 6.5397 6.8539 7.0331
Columns 25 through 28
7.0632 6.9332 6.6350 6.1644
Columns 29 through 32
5.5210 4.7087 3.7357 2.6146
Columns 33 through 36
1.3624 0.0000 -1.4475 -2.9517
Columns 37 through 40
-4.4812 -6.0023 -7.4796 -8.8768
Columns 41 through 44
-10.1574 -11.2860 -12.2286 -12.9538
Columns 45 through 48
-13.4336 -13.6445 -13.5678 -13.1904
Columns 49 through 52
-12.5057 -11.5138 -10.2216 -8.6433
Columns 53 through 56
-6.8004 -4.7211 -2.4406 -0.0000
Columns 57 through 60
2.5541 5.1705 7.7943 10.3680
Columns 61 through 64
12.8330 15.1302 17.2023 18.9942
Columns 65 through 68
20.4549 21.5388 22.2066 22.4269
Columns 69 through 72
22.1767 21.4426 20.2215 18.5207
Columns 73 through 76
16.3583 13.7636 10.7761 7.4455
Columns 77 through 80
3.8310 0.0000 -3.9729 -8.0073
Columns 81 through 84
-12.0185 -15.9195 -19.6226 -23.0412
Columns 85 through 88
-26.0922 -28.6973 -30.7856 -32.2947
Columns 89 through 92
-33.1728 -33.3802 -32.8900 -31.6899
Columns 93 through 96
-29.7823 -27.1851 -23.9314 -20.0697
Columns 97 through 100
-15.6629 -10.7879 -5.5336 -0.0000
H(100,90)
ans =
-33.3802
sa(100)
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> linspace at 22
y = [d1+(0:n-2)*(d2-d1)/(floor(n)-1) d2];
Error in ==> H at 2
x = linspace(pi/2,2*pi,m);
Error in ==> sa>@(i)H(x,i) at 3
Hval = @(i) H(x,i);
Error in ==> sa at 9
Hi = Hval(i);
sa(100)
??? Error using ==> mrdivide
Matrix dimensions must agree.
Error in ==> linspace at 22
y = [d1+(0:n-2)*(d2-d1)/(floor(n)-1) d2];
Error in ==> H at 2
x = linspace(pi/2,2*pi,m);
Error in ==> sa>@(i)H(x,i) at 3
Hval = @(i) H(x,i);
Error in ==> sa at 9
Hi = Hval(i);
sa(100)
counterstati =
42
ans =
-32.8900
sa(100)
counterstati =
54
ans =
-33.3802
sa(100)
counterstati =
59
ans =
-32.2947
sa(100)
counterstati =
46
ans =
-32.2947
sa(100)
counterstati =
54
ans =
-31.6899
sa(100)
counterstati =
46
ans =
-29.7823
sa(100)
counterstati =
64
ans =
-33.3802
sa(100)
counterstati =
69
ans =
-33.1728
sa(100)
counterstati =
44
ans =
-33.1728
sa(100)
counterstati =
22
ans =
-33.1728
sa(100)
counterstati =
37
ans =
-33.3802
sa(100)
counterstati =
44
ans =
-32.8900
sa(200)
counterstati =
29
ans =
-28.8619
sa(200)
counterstati =
40
ans =
-32.8652
sa(200)
counterstati =
28
ans =
-32.8652
sa(1000)
counterstati =
51
ans =
-33.3814
uiopen('/home/accounts/personale/clrmrc90/aa1213/sistemi_stocastici/H.m', true);
x=linspace(pi/2,2*pi,100);
H(x,1:100)
ans =
Columns 1 through 4
-2.4674 -2.5925 -2.6631 -2.6711
Columns 5 through 8
-2.6094 -2.4726 -2.2568 -1.9599
Columns 9 through 12
-1.5822 -1.1260 -0.5962 -0.0000
Columns 13 through 16
0.6530 1.3507 2.0792 2.8223
Columns 17 through 20
3.5625 4.2808 4.9577 5.5729
Columns 21 through 24
6.1067 6.5397 6.8539 7.0331
Columns 25 through 28
7.0632 6.9332 6.6350 6.1644
Columns 29 through 32
5.5210 4.7087 3.7357 2.6146
Columns 33 through 36
1.3624 0.0000 -1.4475 -2.9517
Columns 37 through 40
-4.4812 -6.0023 -7.4796 -8.8768
Columns 41 through 44
-10.1574 -11.2860 -12.2286 -12.9538
Columns 45 through 48
-13.4336 -13.6445 -13.5678 -13.1904
Columns 49 through 52
-12.5057 -11.5138 -10.2216 -8.6433
Columns 53 through 56
-6.8004 -4.7211 -2.4406 -0.0000
Columns 57 through 60
2.5541 5.1705 7.7943 10.3680
Columns 61 through 64
12.8330 15.1302 17.2023 18.9942
Columns 65 through 68
20.4549 21.5388 22.2066 22.4269
Columns 69 through 72
22.1767 21.4426 20.2215 18.5207
Columns 73 through 76
16.3583 13.7636 10.7761 7.4455
Columns 77 through 80
3.8310 0.0000 -3.9729 -8.0073
Columns 81 through 84
-12.0185 -15.9195 -19.6226 -23.0412
Columns 85 through 88
-26.0922 -28.6973 -30.7856 -32.2947
Columns 89 through 92
-33.1728 -33.3802 -32.8900 -31.6899
Columns 93 through 96
-29.7823 -27.1851 -23.9314 -20.0697
Columns 97 through 100
-15.6629 -10.7879 -5.5336 -0.0000
diary off