%% ODE45 equations to be solved
% The following is considered:
% QPM


function dA = ode45equation(z,A,g,deltak,QPM,lcoh)
    dA=zeros(3,1);
    
    %% QPM factor
    %   Effectevely adds a pi phase shift of the induced
    %   polarisation and hence the source term in the
    %   wave-equations every time the wave has traveled
    %   half a coherence length, lcoh
    if QPM == 0 
        s=-1;
    else
        s = -(-1).^floor((z+lcoh/4)/(QPM*lcoh/2));
    end
    
    %% Calculates the solution to the coupled differential equation
    %   A(1) is the signal
    %   A(2) is the idler
    %   A(3) is the pump
    dA(1)   =  s*  1i*g*A(3)*conj(A(2))    *exp(1i*deltak*z)   ;
    dA(2)   =  s*  1i*g*A(3)*conj(A(1))    *exp(1i*deltak*z)   ;
    dA(3)   =  s*  1i*g*A(1)*A(2)          *exp(-1i*deltak*z)  ;
    
%     if( abs(A(1) + dA(1)) < 4e13)
%         disp('signal');
%         dA(1) = -A(1)+abs(A(1))*exp(1i*angle(dA(1)));
%     end
%     
%     if( abs(A(2) + dA(2)) < 1.7733e11)
%         disp('idler');
%         dA(2) = -A(2)+abs(A(2))*exp(1i*angle(dA(2)));
%     end
    
%     if( abs(A(3) + dA(3)) < 5e14)
%         disp('pump');
%         dA(3) = -A(3)+abs(A(3))*exp(1i*angle(dA(3)));
%     end
    
end