function [q] = abcd2self_repeating_q( abcd_cavity ) % this find q such that q = (A*q+B)/(C*q+D) % i.e q after abcd is exactly the same % very handy for cavity mode calculations % spelling out abcd coefficients [A, B, C, D] = abcd2ABCD( abcd_cavity ); if ~isCavityStable(abcd_cavity) display('ABCD is unstable !'); display('We should stop now. There is no stable self-repeating mode with such ABCD'); error('Not possible to calculate a self-repeating mode with the unstable ABCD'); end % q is the solution of quadratic equation, we chose one with positive waist size q = ( -(D-A) - sqrt( (D-A)^2 + 4*C*B ) ) / (2*C); end