1 | function [ztrata control y b P]=rizeni(H,u,system,zac)
|
---|
2 |
|
---|
3 | ztrata=0;
|
---|
4 | index=zac;
|
---|
5 | state=H(1,index,:)
|
---|
6 |
|
---|
7 | for i=1:size(H,1)-1
|
---|
8 | best_control=u(i,index);
|
---|
9 | y(i)=state(1,1,1);
|
---|
10 | b(i)=state(1,1,2);
|
---|
11 | P(i)=state(1,1,3);
|
---|
12 | control(i)=best_control;
|
---|
13 |
|
---|
14 | next_state(1)=state(1)+system.b*best_control+system.sigma*randn;
|
---|
15 | ztrata=ztrata+(next_state(1)-system.yr(i))^2;
|
---|
16 | if i<size(H,1)-1
|
---|
17 | %kalman
|
---|
18 | K=best_control*state(3)/(state(3)*best_control^2+system.sigma^2);
|
---|
19 | next_state(2)=state(2)+K*(next_state(1)-state(1)-state(2)*best_control);
|
---|
20 | next_state(3)=(1-K*best_control)*state(3);
|
---|
21 | state(1,1,:)=next_state;
|
---|
22 | index=find_in_hyperstate5(state,H(i+1,:,:));
|
---|
23 |
|
---|
24 | plot3(H(i+1,:,1),H(i+1,:,2),H(i+1,:,3),'g.');
|
---|
25 | hold on
|
---|
26 | plot3(H(i+1,index,1),H(i+1,index,2),H(i+1,index,3),'r+');
|
---|
27 | plot3(state(1,1,1),state(1,1,2),state(1,1,3),'r+');
|
---|
28 | hold off
|
---|
29 |
|
---|
30 |
|
---|
31 | end
|
---|
32 | end
|
---|
33 |
|
---|
34 | y(size(H,1))=state(1,1,1);
|
---|
35 | b(size(H,1))=state(1,1,2);
|
---|
36 | P(size(H,1))=state(1,1,3);
|
---|
37 | control(size(H,1))=0;
|
---|
38 | end |
---|