function [ phii, phiix ] = phi ( il, x, xleft, xrite ) %% PHI evaluates a linear basis function and its derivative. % % Discussion: % % In any interval, there are just two basis functions. The first % basis function is a line which is 1 at the left endpoint % and 0 at the right. The second basis function is 0 at % the left endpoint and 1 at the right. % % Modified: % % 02 November 2006 % % Parameters: % % Input, integer IL, the index of the basis function. % 1, the function which is 1 at XLEFT and 0 at XRITE. % 2, the function which is 0 at XLEFT and 1 at XRITE. % % Input, real X, the evaluation point. % % Input, real XLEFT, XRITE, the left and right % endpoints of the interval. % % Output, real PHII, PHIIX, the value of the % basis function and its derivative at X. % if ( xleft <= x & x <= xrite ) if ( il == 1 ) phii = ( xrite - x ) / ( xrite - xleft ); phiix = -1.0 / ( xrite - xleft ); else phii = ( x - xleft ) / ( xrite - xleft ); phiix = 1.0 / ( xrite - xleft ); end % % If X is outside of the interval, then the basis function % is always zero. % else phii = 0.0; phiix = 0.0; end