The number \−1 is predefined in MATLAB and stored in the two variable locations denoted by
i and j. This double definition comes from the preference of mathematicians for using i and the preference of engineers for using j (with i denoting electrical current). i and j are variables, and their contents may be changed. If you type j = 5, then this is the value for j and j no longer contains \−1. Type in j = sqrt(-1) to restore the original value. Note the way a complex variable is displayed. If you type i, you should get the answeri =
0+1.0000i.The same value will be displayed for
j. Try it. Using j, you can now enter complex variables. For example, enter z1 = 1+2*j and z2 = 2+1.5*j. As j is a variable, you have to use the multiplication sign *. Otherwise, you will get an error message. MATLAB does not differentiate (except in storage) between a real and a complex variable. Therefore variables may be added, subtracted, multiplied, or even divided. For example, type in x = 2, z = 4.5*j, and z/x. The real and imaginary parts of z are both divided by x. MATLAB just treats the real variablex as a complex variable with a zero imaginary part. A complex variable that happens to have a zero imaginary part is treated like a real variable. Subtract 2*j from z1 and display the result.MATLAB contains several built-in functions to manipulate complex numbers. For example,
real (z) extracts the real part of the complex number z. Type≫ z = 2+1.5*j, real(z)to get the result
z =
2.000+1.500i
ans =
2Similarly,
imag(z) extracts the imaginary part of the complex number z. The functions abs(z) and angle(z) compute the absolute value (magnitude) of the complex number z and its angle (in radians). For example, type≫ z = 2+2*j;
≫ r = abs(z)
≫ theta = angle(z)
≫ z = r*exp(j*theta)The last command shows how to get back the original complex number from its magnitude and angle. This is clarified in Chapter 1: Complex Numbers.
Another useful function,
conj (z), returns the complex conjugate of the complex number z. If z = x+j*y where x and y are real, then conj (z) is equal to x-j*y. Verify this for several complex numbers by using the function conj (z).
0 comments:
Post a Comment