 function [lambdas]=tplottrs(B,g,delta)
%function [lambdas]=tplottrs(B,g,delta)
es=sort(-eig(B));
n=length(es);
epsd=.2;    % adjust gap adjacent to eigenvalues in plot
int=[];
for i=1:n-1,
   int=[int linspace(es(i)+epsd,es(i+1)-epsd)];
end
lasteig=length(int);
int=[int linspace(es(n)+epsd,es(n)+20)];
  
k=length(int);
normplam=zeros(k,1);
for i=1:k,
  normplam(i)=norm(-(B+int(i)*eye(n))\g);
end
normplam=1./normplam;
delta=1/delta;
difft=abs(normplam-delta);
difft(1:lasteig)=difft(1:lasteig)+10;
[iv,i]=min(difft);
lambdas=int(i);
plot(int,normplam,'r');
hold on
plot(es,zeros(n,1),'rx')
plot(int(i),normplam(i),'co')
disp(['graphical solution for lambda^* is: ',num2str(lambdas)]);
plot(int,delta*ones(k,1))
hold off
