function fv=fitSingle(globalPar, par, cax)
    %par is a nfunc x npar matrix of coefficients
    %globalPar is a row vector of global coefficients
    %cax is a column vector of time instances
    %cay are the function values
    
    %oneVector=ones(1,size(cax,1));%column vector
    
    A=globalPar(1);
    tau=globalPar(2);
    t0=globalPar(5);
    t1=globalPar(6);
    
    k1=par(1);
    B=par(2);
    k2=par(3);
    
    
    kt=k1./(1/tau-k2);
    e0=exp(-(cax-t1)/tau);
    ek=exp(-(cax-t1).*k2);
    
    ek1=(1-exp(-k2.*(cax-t0)))./(k2*(t1-t0));
    fk1=(1-exp(-k2*(t1-t0)))./(k2*(t1-t0));
    fr1=k1./k2.*(1-fk1);
    B1=1-B;
    
    dt=(cax-t0)/(t1-t0);
    
    if k2==1/tau
        r0=k1*(cax-t1).*e0;
    else
        r0=kt*(ek-e0);
    
    fv=zeros(size(cax));
    sel=cax>t0 & cax<=t1;
    fv(sel)=B*dt(sel)+B1*k1/k2*(dt(sel)-ek1(sel));
    
   
    sel=cax>t1;
    
    fv(sel)=B*e0(sel)+B1*(fr1+r0(sel));
    
    
    fv=fv*A;
    

end

%par=ones(2,