Skip to main content
Engineering LibreTexts

8.6: Complex Variables

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    The number \(\sqrt{-1}\) is predefined in MATLAB and stored in the two variable locations denoted byiandj. 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).iandjare variables, and their contents may be changed. If you typej = 5, then this is the value forjandjno longer contains \(\sqrt{-1}\). Type inj = sqrt(-1)to restore the original value. Note the way a complex variable is displayed. If you typei, you should get the answer

    i =

    The same value will be displayed forj. Try it. Usingj, you can now enter complex variables. For example, enterz1 = 1+2*jandz2 = 2+1.5*j. Asj 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 inx = 2, z = 4.5*j, and z/x. The real and imaginary parts of z are both divided byx. 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. Subtract2*jfromz1 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 =
    ans =

    Similarly, 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).

    This page titled 8.6: Complex Variables is shared under a CC BY 3.0 license and was authored, remixed, and/or curated by Louis Scharf (OpenStax CNX) via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?