>>eqn = [1 6 25] eqn = 1 6 25and ask for the roots:
>>roots(eqn) ans = -3.0000 + 4.0000i -3.0000 - 4.0000iNotice that this is the same answer as given in the book.
MATLAB outputs \(i\) as the square root of \(-1\), but
you can use \(j\) too.
Manipulating complex numbers
There are many commands for manipulating complex numbers.
You can guess what they do by their names.
>>z = 3 + j*4 z = 3.0000 + 4.0000i >>real(z) ans = 3 >>imag(z) ans = 4 >>conj(z) ans = 3.0000 - 4.0000i >>abs(z) ans = 5 >>angle(z) ans = 0.9273Note the angle is in radians, you can convert to degrees by:
>>angle(z)*180/pi ans = 53.1301If you want to input as polar use:
>>z2=10*exp(j*pi/4) z2 = 7.0711 + 7.0711ior
>>10*exp(j*45/180*pi) ans = 7.0711 + 7.0711iA handy way to see a complex number in several forms is zprint. zprint is not part of MATLAB, but comes with this CD-ROM
>>zprint([z,z2]) Z = X + jY Magnitude Phase Ph/pi Ph(deg) 3 4 5 0.927 0.295 53.13 7.071 7.071 10 0.785 0.250 45.00Type help zprint for more details
zvect([z, z2])
zcat([z, z2])
zvect([z, z2]) axis([-8 8 -8 8])
The example from section 2.4.1 via MATLAB is:
>>z1 = 7*exp(j*4*pi/7) z1 = -1.5576 + 6.8245i >>z2 = 5*exp(-j*5*pi/11) z2 = 0.7116 - 4.9491iNotice MATLAB automatically converts them to rectangular form. Now just add them.
>>z3 = z1 + z2 z3 = -0.8461 + 1.8754iWe can also show this graphically with:
>>zcat([z1, z2]), hold on >>zvect(z3)
>>p = [1 0 0 -1] p = 1 0 0 -1 >>z = roots(p) z = -0.5000 + 0.8660i -0.5000 - 0.8660i 1.0000You can check to see if you have the right polynomial with the poly2sym command.
>>poly2sym(p,'z') ans = z^3-1Good, it checks.
We might see a pattern if we convert to polar.
>>zprint(z) Z = X + jY Magnitude Phase Ph/pi Ph(deg) -0.5 0.866 1 2.094 0.667 120.00 -0.5 -0.866 1 -2.094 -0.667 -120.00 1 0 1 0.000 0.000 0.00Hmmm, do you see the pattern? Let's plot them.
zvect(z)
>>z10 = roots([1 0 0 0 0 0 0 0 0 0 -1]) zvect(z10) z10 = -1.0000 -0.8090 + 0.5878i -0.8090 - 0.5878i -0.3090 + 0.9511i -0.3090 - 0.9511i 0.3090 + 0.9511i 0.3090 - 0.9511i 1.0000 0.8090 + 0.5878i 0.8090 - 0.5878i >>zprint(z10) Z = X + jY Magnitude Phase Ph/pi Ph(deg) -1 0 1 3.142 1.000 180.00 -0.809 0.5878 1 2.513 0.800 144.00 -0.809 -0.5878 1 -2.513 -0.800 -144.00 -0.309 0.9511 1 1.885 0.600 108.00 -0.309 -0.9511 1 -1.885 -0.600 -108.00 0.309 0.9511 1 1.257 0.400 72.00 0.309 -0.9511 1 -1.257 -0.400 -72.00 1 0 1 0.000 0.000 0.00 0.809 0.5878 1 0.628 0.200 36.00 0.809 -0.5878 1 -0.628 -0.200 -36.00>>zvect(z10)