<img src="https://d5nxst8fruw4z.cloudfront.net/atrk.gif?account=iA1Pi1a8Dy00ym" style="display:none" height="1" width="1" alt="" />
Dismiss
Skip Navigation

3.4: Basic Complex and Matrix Operations

Difficulty Level: At Grade Created by: CK-12
Turn In

Complex numbers

m-file environments have excellent support for complex numbers. The imaginary unit is denoted by

i

or

(as preferred in Electrical Engineering)

j

.

To create complex variables \begin{align*}z_1 = 7 + j\end{align*}z1=7+j and \begin{align*}z_2 = 2e^{j\pi}\end{align*}z2=2ejπ simply enter

z1 = 7 + j

and

z2 = 2*exp(j*pi)

Table 2 gives an overview of the basic functions for manipulating complex numbers, where \begin{align*}z\end{align*}z is a complex number.

Manipulating complex numbers.
m-file
\begin{align*}Re(z)\end{align*}Re(z)
real(z)
\begin{align*}Im(z)\end{align*}Im(z)
imag(z)
\begin{align*}mag(z)\end{align*}mag(z)
abs(z)
\begin{align*}\angle(z)\end{align*}(z)
angle(z)
\begin{align*}z^*\end{align*}z
conj(z)

Operations on Matrices

In addition to scalars, m-file environments can operate on matrices. Some common matrix operations are shown in Table 3; in this table,

M

and

N

are matrices.

Common matrix operations.
Operation m-file
\begin{align*}M N\end{align*}MN
M*N
\begin{align*}M^{-1}\end{align*}M1
inv(M)
\begin{align*}M^T\end{align*}MT
M' 
\begin{align*}det(M)\end{align*}det(M)
det(M)

Some useful facts:

  • The functions
    length
    

    and

    size
    

    are used to find the dimensions of vectors and matrices, respectively.

  • Operations can also be performed on each element of a vector or matrix by proceeding the operator by ".", e.g
    .*
    

    ,

    .^
    

    and

    ./
    

    .

Example 4

Let \begin{align*}A = \begin{pmatrix}1 & 1\\ 1 & 1\end{pmatrix}\end{align*}A=(1111). Then

A^2

will return \begin{align*}AA = \begin{pmatrix}2 & 2\\ 2 & 2\end{pmatrix}\end{align*}, while

A.^2

will return \begin{align*}\begin{pmatrix}1^2 & 1^2\\ 1^2 & 1^2\end{pmatrix} = \begin{pmatrix}1 & 1\\ 1 & 1\end{pmatrix}\end{align*}.

Example 5

Given a vector

x

,

compute a vector

y

having elements \begin{align*}y (n) = \tfrac{1}{sin(x(n))}\end{align*}. This can be easily be done with the command

y=1./sin(x)

Note that using

/

in place of

./

would result in the (common) error "Matrix dimensions must agree".

Notes/Highlights Having trouble? Report an issue.

Color Highlighted Text Notes
Please to create your own Highlights / Notes
Show More

Image Attributions

Show Hide Details
Files can only be attached to the latest version of section
Please wait...
Please wait...
Image Detail
Sizes: Medium | Original
 
CK.ENG.ENG.SE.1.Engineering-Matlab.3.4