function f = lmaxpdf3vec(x,l,w,gbar,Etaext,Rext)
C = length(x);
R = length(Etaext(2:end-1));
X = repmat(x,R,1);
s_l = repmat(l/w*((Etaext(2:end-1)-Etaext(1:end-2))./(Rext(2:end-1)-Rext(1:end-2)))',1,C);
s_u = repmat(l/w*((Etaext(3:end)-Etaext(2:end-1))./(Rext(3:end)-Rext(2:end-1))),1,C);
maxwR = max(w*repmat(Rext(2:end-1)',1,C)-X,0);
fg = repmat(l*Etaext(2:end-1)./maxwR;
fg(isnan(fg)) = inf;
fvec = exppdf(fg,gbar).*(l*Etaext(2:end-1)./maxwR.^2);
fvec((fg>=s_u)|(fg<=s_l)) = 0;
f = sum(fvec);
end