function [q, q_lens] = gbeam_propagation(x_pos, q_in, x_in, optics_elements) % calculate the 'q' parameter of the Gaussian beam propagating through optical % 'optics_elements' array along 'x' axis at points 'x_pos' % takes the gaussian beam with initial q_in parameter at x_in % x_pos must be monotonic! q=0*x_pos; % q vector initialization if any(x_pos >= x_in) % Forward propagation to the right of x_in [q(x_pos >= x_in), q_lens] = gbeam_propagation_froward_only(x_pos(x_pos>=x_in), q_in, x_in, optics_elements); end if any(x_pos < x_in) % Backward propagation part the left of x_in % do it as forward propagation of the reverse beam x_backw=x_pos(x_pos