L=1;

% k*L should be around 2 otherwise derivative of the inner function has wrong slope
% more precisely something like pi*N + 2
%k=2;      % the lowest energy k value
k=2+1*pi;  % 2nd energy level k value
%k=2+2*pi; % 3rd energy level k value


merit = @(v) merit_psi(v, k, L);

[v_opt, merit_At_optimum]=fminsearch(merit, [.11,1]);
alpha=v_opt(1);
B=v_opt(2);

x=linspace(0,2*L,1000);
plot( ...
	x(x<L), sin(k*x(x<L)), ...
	x(x>L), B*exp(-alpha.*x(x>L)) ...
	)
set(gca,'fontsize',20); 
legend('inner psi', 'outer psi');	
xlabel('x');	
ylabel('Psi');	


