%This function successfully (!) returns the maximum value of n
function [gopt,nmax] = maxnforpt()%Pt,pe)

global Pt
global log10pe
global R;


gstart = hbinv(1-R);
[gopt,nmax2,exitflag] = fminbnd(@returnnforg2,gstart,0.5);  

nmax = -nmax2;

  
    
    