{
Inverted calibration, i.e. find x=invCalibr(n,y,z,a,b),
for which y=Calibr(n,x,z). Assume that x may vary in range (a,b).
Return NAN in case of any error(s).
}
function invCalibr(n:Integer; y,z,a,b:Real):Real;
const MaxIter=128;
var i,k,ia,ib,it:Integer; t:Real;
begin
 k:=0;
 if a>b then begin t:=a; a:=b; b:=t; end;
 ia:=Sign(Calibr(n,a,z)-y); k:=k+1;
 if ia=0 then t:=a else begin
  ib:=Sign(Calibr(n,b,z)-y); k:=k+1;
  if ib=0 then t:=b else begin
   i:=0;
   while i<MaxIter do begin
    t:=a+(b-a)*0.5;
    it:=Sign(Calibr(n,t,z)-y); k:=k+1;
    if t=a then i:=MaxIter else
    if t=b then i:=MaxIter else
    if it=0 then i:=MaxIter else
    if it*ia<0 then begin b:=t; ib:=it; end else
    if it*ib<0 then begin a:=t; ia:=it; end else begin t:=_NaN; i:=MaxIter; end;
    i:=i+1;
   end;
  end;
 end;
 invCalibr:=t;
end;
