function odeOutput = swingEquation_multiMachine_withDamping(t,x,E, M, D, Y, pm)
%swingEquation This function implements the multimachine swing equation for use with a
%numerical ODE solver.

% x is assembled as: first "n" rows = rotor angles, next "n" rows = rotor
% speeds -- all angles in radians
n = length(x)/2;
for (i=1:n)
    pe = 0;
    for (k=1:n)
        pe = pe + abs(E(i))*abs(E(k))*(real(Y(i,k))*cos(x(i)-x(k)) + imag(Y(i,k))*sin(x(i)-x(k)));
    end
    x_dot(i) = x(i+n);
    x_dot(i+n) = (pm(i) - pe - D(i)*x_dot(i))/M(i);
end

odeOutput = [transpose(x_dot)];

end

