root/applications/dual/SIDP/smc29/smc_simple.m @ 1344

Revision 1255, 1.0 kB (checked in by zimamiro, 14 years ago)
Line 
1function smc_simple(N,n)
2system.sigma=0.01;
3system.ny=0.02;
4
5system.x=0.5;
6apriori=[0 1];
7
8x_1=apriori(:,1)*ones(1,N)+apriori(:,2:end)*(0.5-rand(1,N)); vahy=1/N*ones(1,N);
9N_tresh=N/2;
10stav=[]; hranice=stav;
11
12for i=1:n
13    x_0=my_sample(vahy,x_1);
14   
15    x_1=model_simple(x_0,system);
16   
17    system.x=model_simple(system.x,system);
18    system.pozorovani=system.x+sqrt(system.ny)*randn;
19   
20    reziduum=system.pozorovani*ones(1,N)-x_1;
21    p_v=exp(-(reziduum.^2/system.ny)/2);
22    vahy=p_v/sum(p_v);
23   
24   %porovnani(x_1,vahy,system.x);
25   
26    if (1/(vahy*vahy')<N_tresh)
27        [x_1 vahy]=my_resample(x_1,vahy);
28       % porovnani(x_1(1,:),vahy,system.x(1));
29    end
30
31    %x_0=my_sample(vahy,x_1);   
32    %H=kalman_filter(H,u(:,i),system);
33   
34    stav=[stav [system.x; mean(x_1,2)]];
35    hranice=[hranice [min(x_1,[],2); max(x_1,[],2)]];
36    %ztrata= ztrata+u'*system.gamma*u+(system.x-system.x_opt)'*system.ksi*(system.x-system.x_opt);
37
38end
39%plot(abs(stav(1,:)-stav(2,:))); hold on
40kresli(stav,hranice)
41end
Note: See TracBrowser for help on using the browser.