
function[val] = interpol_operator(phi_vec,x_vec,x)

brk = 0;
index = 1;

while brk == 0
    
   
    
    if (x_vec(index)<= x ) && (x_vec(index+1)>= x)
        
        val = phi_vec(index+1)*(x-x_vec(index))/(x_vec(index+1)-x_vec(index)) + phi_vec(index)*(-x + x_vec(index+1))/(x_vec(index+1)-x_vec(index));
        
        brk = 1;
    end
    
     if (index == length(x_vec)-1) && (x > x_vec(end))
       
        val = phi_vec(end);
        brk = 1;
        
     elseif (index == length(x_vec)-1) && (x < x_vec(1))
         
         val = phi_vec(1);
         brk = 1;
    end
    
index = index +1;  
end