%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Illustration of MATLAB complex arithmetic features %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Both i and j are pre-defined to the unit imaginary number ... i j i^2 j^2 % Define a complex constant in the obvious/natural way ... z1 = 3 + 4 * i z2 = 3 - 4 * i % Complex numbers can be used in general arithmetic expressions ... z1 * z2 % Note how the result of this division is in normal form ... z1 / z2 z1^2 + z2^2 % The 'complex' function can also be used to make complex numnbers, and % is especially convenient for creating arrays of them ... v1 = 1 : 5 v2 = -5 : -1 zv1 = complex(v1, v2) % Useful functions for manipulating complex values ... % abs -> compute modulus abs(zv1) % real -> returns real part of argument % imag -> returns imag part of argument real(zv1) imag(zv1) % conj -> complex conjugate conj(zv1) zv1 + conj(zv1) imag(zv1 + conj(zv1)) % angle -> phase angle theta = linspace(0, 2*pi, 17) zth = exp(i*theta) ztheta = phase(zth) ztheta - theta