clear all; close all;



g0 = 0.7/2;

tauL = 0.87e-6; 

E_L = 0.2e-6;

P_L = E_L/tauL;



T_R = 2.7e-12;

T_L = tauL/T_R;



l = 0.14/2;



% Fast saturable absorber

q0 = 0.03/2;

tauA = 1e-12;

E_A = 0.77e-12;

P_A = E_A/tauA;



P = linspace(0,5,1000); % [W]

g = g0./(1+P/P_L);

q = q0./(1+P/P_A);

plot(P,g); hold on; grid on;

plot(P,q+l,'r');

plot([min(P) max(P)],l*[1 1],'r--');

xlabel('CW power [W]');

ylabel('Gain and losses, g(P), l+q(P)');

legend('g','l+q','l','Location','Best');

title('6.638: PS5, Problem 5.2a');



x = g-l-q;

[m mIndex] = min(abs(x));

Pcw = P(mIndex);

gcw = g(mIndex);

qcw = q(mIndex);

clear x;



% Stability criterion

p = Pcw/P_L;

x = P_A/P_L;

LHS = 2*T_L*q0*(p/x)/(1+(p/x))^2;

RHS = 1+Pcw/P_L;