%% Frank's solution to the transfer/rate problem via Laplace transform
x0 = 2;
% D_p = 0.85;
% D_m = 0.15;
D_m = g0(1)*(1-u0-e); % to make equal to ternary FRAP
D_p = g0(end)*(1-u0);
ga = 1/9;

p_out = @(D_p, D_m, ga, x0, x, t) 1./(2*sqrt(D_p*pi*t))*...
            (exp(-(x+x0).^2./(4*D_p*t))*(ga*sqrt(D_p)-sqrt(D_m))./...
            (ga*sqrt(D_p)+sqrt(D_m))+exp(-(x-x0).^2./(4*D_p*t)));
p_in = @(D_p, D_m, ga, x0, x, t) 1./(sqrt(pi*t)*(sqrt(D_m)+ga*sqrt(D_p)))*...
            exp(-(x-x0*sqrt(D_m/D_p)).^2/(4*D_m*t));
x_left = linspace(-4, 0, 1000);
x_right = linspace(0, 4, 1000);

%% Plot with full ternary model

for i = 1:200
    figure(2); hold on; cla;
    j = i+2;
    plot(x_left, p_in(D_p, D_m, ga, x0, x_left, j/100));
    plot(x_right, p_out(D_p, D_m, ga, x0, x_right, j/100));
    plot(x+a, sol(i, :), 'LineWidth', 2);
    axis([-1, 3, 0, 0.7]);
    shg; pause();
end
