% Subtraction can be defined in terms of addition % and the additive inverse. % % If % % w = a + bj % % and % % z = c + dj, % % then % % w - z = w + (-z) % % = (a + bj) + (-c - dj) % % = (a - c) + (b - d)j. % % Thus, complex numbers are subtracted by % subtracting their real components and their % imaginary components separately. w = 5.3 + 3.2j z = 3.2 - 4.7j fprintf('\nCalculations with subtraction:\n') w - z % We can obtain the same result by adding the % additive inverse of z to w. w + (-z) % Addition is commutative, so we can also add % the two numbers in the opposite order. (-z) + w % Thus, % % w - z = w + (-z) = (-z) + w. fprintf('\nEquivalent ways of calculating w - z:\n') w - z w + (-z) (-z) + w % We can also see how subtraction is performed % by separately subtracting the real and % imaginary components. real(w) - real(z) imag(w) - imag(z) fprintf('Re(w) - Re(z) = %f\n', ... real(w) - real(z)) fprintf('Im(w) - Im(z) = %f\n', ... imag(w) - imag(z)) % Putting these two components back together % gives the difference of the two complex % numbers. fprintf('(Re(w) - Re(z)) + j(Im(w) - Im(z)) = %f%+fj\n\n', ... real(w) - real(z), ... imag(w) - imag(z)) % Thus, % % Re(w - z) = Re(w) - Re(z) % % and % % Im(w - z) = Im(w) - Im(z). % Unlike addition, subtraction is not % commutative. In general, % % w - z ~= z - w. % % Instead, reversing the order gives the % additive inverse: % % w - z = -(z - w). fprintf('\nReversing the order of subtraction:\n') w - z z - w -(z - w) % Confirm that % % w - z = -(z - w). (w - z) == -(z - w) % Subtracting a number from itself gives zero. fprintf('\nSubtracting a number from itself:\n') w - w z - z % Subtracting zero does not change a number. fprintf('\nSubtracting zero:\n') w - 0 z - 0 % Subtracting a number from zero gives its % additive inverse. fprintf('\nSubtracting a number from zero:\n') 0 - w -w 0 - z -z % Thus, % % w - 0 = w % % while % % 0 - w = -w. % Subtracting an additive inverse is equivalent % to addition: % % w - (-z) = w + z. fprintf('\nSubtracting an additive inverse:\n') w - (-z) w + z (w - (-z)) == (w + z) % Parentheses are important when more than two % numbers are being subtracted. Subtraction is % not associative. In general, % % (w - z) - v ~= w - (z - v). v = -1.8 + 2.1j fprintf('\nSubtraction is not associative:\n') (w - z) - v w - (z - v) % The first expression can be written as % % (w - z) - v % = w + (-z) + (-v) % = w - z - v. % % The second expression is % % w - (z - v) % = w - z + v. % % Consequently, these expressions generally % have different values. ((w - z) - v) == (w - (z - v))