function [H_new zero range eigvec u]=update_hyperstate(H_old,zero, range, eigvec, u,n_grid,sigma,H_full)

next_u=zeros(1,size(H_old,2));

step=[1 n_grid n_grid^2];
rozsah_min=[1;0;0];
rozsah_max=[n_grid; n_grid-1; n_grid-1];
stav1=zeros(3,1);

H_new=generate_trajectories(H_old,u,sigma);
    
for i=2:size(H_new,1)
     pom(:,:)=H_new(i,:,:);
    [H_new(i,:,:) next_zero next_range next_eigvec]=make_box3(pom,n_grid); %rovnomerne rozmisti body v zasazenem regionu
    

    if (H_full)  %kopirovani stareho u* do H_new  
        for j=1:size(H_new,2)
            stav(1)=H_new(i,j,1)-zero(i,1);
             stav(2)=H_new(i,j,2)-zero(i,2);
              stav(3)=H_new(i,j,3)-zero(i,3);                  
            for p=1:3
                stav1(p)=(stav(1)*eigvec(i,1,p)+stav(2)*eigvec(i,2,p)+stav(3)*eigvec(i,3,p))*range(i,p);
            end
            index=step*max(min(round(stav1*(n_grid-1))+rozsah_min,rozsah_max),rozsah_min);
    
            next_u(j)=u(i,index);
        end
        
        for j=1:size(H_new,2)
            u(i,j)= next_u(j);
        end
    end
    
    zero(i,:)=next_zero;
    range(i,:)=next_range;
    eigvec(i,:,:)=next_eigvec;
end
end