function [x, err]=dist_max(epsilon)
%
% INPUT:
%  epsilon: the small parameter
% OUTOUT:
%  x:       the location where the maximum distance is attained
%  err:     the maximum distance between the exact solution and
%           the asymptotic solution
%
r1=(-1+sqrt(1-4*epsilon))/(2*epsilon);
r2=(-1-sqrt(1-4*epsilon))/(2*epsilon);
y_e = @(x) (exp(r1*x)-exp(r2*x))/(exp(r1)-exp(r2)); % exact solution
y_a = @(x) exp(1-x)-exp(1-x/epsilon);       % asymptotic solution
% y_a = @(x) exp(1-x).*(1+epsilon*(1-x))-exp(1-x/epsilon).*(1+epsilon+x);
G = @(x) -((x>0)&(x<1)).*abs(y_a(x)-y_e(x));  % the function to minimize
%
% Use fminsearch to minimize the function
%
x0=0.5;
options = optimset('TolX',1e-14,'MaxIter',1000);
[x0, fval, flag]=fminsearch(@(x) G(x), x0, options);
x=x0;
err=-fval;
%
%