function [ ret ] = DetermineBoundaryLayer(y, Solution, Inital )
L=length(y);
dY=1/L;
ret=zeros(2,1);
Inital=0.74.*(1+exp(-Inital)).^(-1);
Solution=0.74.*(1+exp(-Solution)).^(-1);
half=ceil(L/2);
lowerHalf=Solution(1:half);
upperHalf=Solution(half+1:end);
Inital1 = Inital*1.01;
Inital2 = Inital*0.99;
if(Solution(1)>Inital)
    [lc, lIdx] = min(abs(lowerHalf-Inital1));
    if lowerHalf(lIdx)-Inital1>0 || lIdx==1
        m=-(lowerHalf(lIdx)-lowerHalf(lIdx+1))/dY;
        b=lowerHalf(lIdx)-y(lIdx)*m;
        ret(1)=(Inital1-b)/m;
    else
        m=-(lowerHalf(lIdx-1)-lowerHalf(lIdx))/dY;
        b=lowerHalf(lIdx)-y(lIdx)*m;
        ret(1)=(Inital1-b)/m;
    end
else
    [lc, lIdx] = min(abs(lowerHalf-Inital2));
    if lowerHalf(lIdx)-Inital2>0 || lIdx==1
        m=-(lowerHalf(lIdx)-lowerHalf(lIdx+1))/dY;
        b=lowerHalf(lIdx)-y(lIdx)*m;
        ret(1)=(Inital2-b)/m;
    else
        m=-(lowerHalf(lIdx-1)-lowerHalf(lIdx))/dY;
        b=lowerHalf(lIdx)-y(lIdx)*m;
        ret(1)=(Inital2-b)/m;
    end
end
if(Solution(end)>Inital)
    [uc, uIdx] = min(abs(upperHalf-Inital1));
    if upperHalf(uIdx)-Inital1>0 || uIdx==L
        m=-(upperHalf(uIdx-1)-upperHalf(uIdx))/dY;
        b=upperHalf(uIdx-1)-y(half+uIdx)*m;
        ret(2)=(Inital1-b)/m;
    else
        m=-(upperHalf(uIdx-1)-upperHalf(uIdx))/dY;
        b=upperHalf(uIdx-1)-y(half+uIdx)*m;
        ret(2)=(Inital1-b)/m;
    end
else
    [uc, uIdx] = min(abs(upperHalf-Inital2));
    if upperHalf(uIdx)-Inital1>0 || uIdx==L
        m=-(upperHalf(uIdx-1)-upperHalf(uIdx))/dY;
        b=upperHalf(uIdx)-y(half+1+uIdx)*m;
        ret(2)=(Inital2-b)/m;
    else
        m=-(upperHalf(uIdx-1)-upperHalf(uIdx))/dY;
        b=upperHalf(uIdx-1)-y(half+uIdx)*m;
        ret(2)=(Inital2-b)/m;
    end
end
end

