k=(1:15)*pi;                       % frequencies to be treated   
alpha=0.625; beta=0.375;           % overlap parameters  
rhoOSM2=@(p) (-k.*cosh(k*(1-alpha))+p(1)*sinh(k*(1-alpha)))...
  ./(k.*cosh(k*alpha)+p(1)*sinh(k*alpha))...
  .*(-k.*cosh(k*beta)+p(2)*sinh(k*beta))...
  ./(k.*cosh(k*(1-beta))+p(2)*sinh(k*(1-beta)));
rhoOSM=@(p) rhoOSM2([p p]);        % when using only one parameter  
R2=@(p) max(abs(rhoOSM2(p)));      % functions giving the maximum
R=@(p) max(abs(rhoOSM(p)));        % to use in the minimization
[p2opt,R2opt]=fminsearch(R2,[1 2]) % minimize with p1 and p2
[popt,Ropt]=fminsearch(R,1)        % minimize with p1=p2=p
rhoS=sinh(k*beta)./sinh(k*(1-beta)).*sinh(k*(1-alpha))...
  ./sinh(k*alpha);                 % classical Schwarz
plot(k,rhoS,'-o',k,rhoOSM(popt),'-+',k,rhoOSM2(p2opt),'-*');
xlabel('k');
legend('Classical Schwarz','Optimized Schwarz','Optimized Schwarz 2p');