reverse-shooting

Matlab scripts for reverse shooting
Log | Files | Refs | README

invchicdf.m (435B)


      1 % invchicdf.m  ord = invchicdf(p,n)
      2 %	Returns the ordinate when given an abscissa
      3 %  Bad way:  do a binary search by calling chicdf repeatedly.
      4 
      5 function ord = invchicdf(p,n);
      6 
      7 tol=.0001;
      8 err = 1;
      9 ord = n/2*sqrt(p/.10);
     10 hi=ord+5;
     11 lo=0;
     12 
     13 while abs(err)>tol;
     14 	phat=chicdf(ord,n)
     15 	err=phat-p
     16 	ordo=ord;
     17 	if err<0; ord=.5*(ord+hi); if ordo>lo; lo=ordo; end;
     18 	else;     ord=.5*(ord+lo); if ordo<hi; hi=ordo; end;
     19 	end;
     20 	[ord hi lo]
     21 end;  
     22