root/applications/dual/SIDP/generate_realization.m @ 743

Revision 743, 0.9 kB (checked in by zimamiro, 14 years ago)
Line 
1function cost=generate_realization(start, candidate, H,u,sigma,yr)
2
3state=start;
4best_control=candidate;
5cost=0;
6num_of_point=(size(H,2))^(1/3);
7
8for i=1:size(H,1)
9   
10    %aplication of best_control
11    next_state(1)=state(1)+(state(2)+state(3)*randn)*best_control+sigma*randn;
12   
13    %kalman
14    K=best_control*state(3)/(state(3)*best_control^2+sigma^2);
15    next_state(2)=state(2)+K*(next_state(1)-state(1)-state(2)*best_control);
16    next_state(3)=(1-K*best_control)*state(3);
17   
18    cost=cost+(state(1)-yr(i))^2;
19   
20    if i<size(H,1)
21        state=next_state;
22       
23        %find in H
24        index=0;
25        for j=1:size(H,3)
26            index=index+(max(min(round((state(j)-H(i,1,j))/(H(i,size(H,2),j)-H(i,1,j))*num_of_point),num_of_point),1)- j>1)^num_of_point^(j-1);
27        end
28       
29        best_control=u(i,index);
30    end
31end
32
33end
Note: See TracBrowser for help on using the browser.