Revision 862, 0.9 kB
(checked in by zimamiro, 14 years ago)
|
|
Rev | Line | |
---|
[862] | 1 | function cost=generate_realization(start, candidate, H,u,sigma,yr)
|
---|
| 2 |
|
---|
| 3 | state=start;
|
---|
| 4 | best_control=candidate;
|
---|
| 5 | cost=0;
|
---|
| 6 | num_of_point=(size(H,2))^(1/3);
|
---|
| 7 |
|
---|
| 8 | for 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
|
---|
| 31 | end
|
---|
| 32 |
|
---|
| 33 | end |
---|