% Written by Min-Hua Huang
% June 9, 2011
% This is a file to calculate the inverse "h" function by numerical analysis. 
% input: hinv(k,s); k:the value of the h function; s:the base parameter.
% Due to the limited computational capacity, when k<0.05,
% the result may be invalid.
function fv=hinv(k,s)
d=1; c=10; m=1; 
while abs(d)>10^-9
    sign0=sign(h(s,c,0)-k);
    sign1=sign0;
    if abs(h(s,c,0)-k)==0
       break;
    end
    if sign0<0  % c is right to the answer 
        while sign1==sign0 
           c=c-m;
           temp=h(s,c,0)-k;
           sign1=sign(temp);
        end
    end
    if sign0>0  % c is left to the answer 
        while sign1==sign0 
          c=c+m;
          temp=h(s,c,0)-k;
          sign1=sign(temp);
        end
    end
m=m/10;
d=temp;
end
fv=c; 


