function sX = fCondition1(fFt,sXprev) % This function checks whether conditon 1 holds for f_t, so that the % characterization theorem can be applied. % Details: "Optimal sequential contests" by Toomas Hinnosaar % avalable at http://toomas.hinnosaar.net/contests.pdf % Matlab code written by Toomas Hinnosaar (toomas@hinnosaar.net) % Inputs: fFt,sXprev = a function f_t and the highest root of f_{t+1} % Returns: the highest root of f_t in [sX,1] (if condition is satisfied) % and -1 otherwise sErr = 0; [sX,sFmin] = fHighestRoot(fFt,sXprev,1); options = optimset('Display','none','TolX',1e-8); if abs(sFmin)>1e-5 sErr = -1; fprintf('1. Could not find a root in [%0.5f,1]',sXprev); else if sX-sXprev>1e-7 % If sX>sXprev, checking if has positive values between by finding max [~,sndFmax] = fminbnd(@(x)(-fFt(x)),sXprev,sX); else sndFmax = 1; end if sndFmax<-1e-6 sErr = -2; fprintf('2. Function takes value %0.5f in [%0.5f,%0.5f]',-sndFmax,sXprev,sX); else X=sym('X'); fdFt = simplify(diff(fFt,X)); if min(size(symvar(fdFt)))>0 fdFtX = matlabFunction(fdFt); else fdFtX = @(X)fdFt(); end [~,sdFtmin] = fminbnd(fdFtX,sX,1,options); if sdFtmin<0 sErr = -3; fprintf('3. Function is not strictly increasing in [%0.5f,1]',sX); end end end if sErr<0 sX = sErr; end function [sRoot,sFval]=fHighestRoot(fF,sMin,sMax) sEps = (sMax-sMin)/2^15; options = optimset('Display','none','TolX',1e-8); for k=1:16 sLB = sMin-sEps+(sMax-sMin)/2^k; sRoot = fminbnd(@(x)(fF(x)).^2,sLB,sMax,options); sFval = fF(sRoot); if abs(sFval)<1e-7 break end end end end