function B = BASIS_function(J,X,T)  
% mitonim BCLEFT, BCRIGHT ro hamin ja fara bekhonim va dg global nagzarim chon global gozashtim pas bayad inja vorodie function bashe

N= length(X);


    value=0;
         if (J==1) 
           if (T < X(2)); 
               value = (X(2)-T)/(X(2)-X(1)); 
           end
         elseif (1<J<N)
             if X(J-1)<T && T <=X(J)
                 value=(T-X(J-1))/(X(J)-X(J-1));
             elseif (X(J) <=T && T < X(J+1))
                 value=(X(J+1)-T)/(X(J+1)-X(J));
             end
         elseif (J==N)
             if (X(N-1)< T && T <= X(N))
                 value= (T-X(N-1))/(X(N)-X(N-1));
             end
         end 
   B=value;      
end