function cost=generate_realization(start, candidate, H,u,sigma,yr) state=start; best_control=candidate; cost=0; num_of_point=(size(H,2))^(1/3); for i=1:size(H,1) %aplication of best_control next_state(1)=state(1)+(state(2)+state(3)*randn)*best_control+sigma*randn; %kalman K=best_control*state(3)/(state(3)*best_control^2+sigma^2); next_state(2)=state(2)+K*(next_state(1)-state(1)-state(2)*best_control); next_state(3)=(1-K*best_control)*state(3); cost=cost+(state(1)-yr(i))^2; if i1)^num_of_point^(j-1); end best_control=u(i,index); end end end