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

# 3.4: Basic Complex and Matrix Operations

Difficulty Level: At Grade Created by: CK-12

## 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 z1=7+j\begin{align*}z_1 = 7 + j\end{align*} and z2=2ejπ\begin{align*}z_2 = 2e^{j\pi}\end{align*} 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 z\begin{align*}z\end{align*} is a complex number.

Manipulating complex numbers.
m-file
Re(z)\begin{align*}Re(z)\end{align*}
real(z)

Im(z)\begin{align*}Im(z)\end{align*}
imag(z)

mag(z)\begin{align*}mag(z)\end{align*}
abs(z)

(z)\begin{align*}\angle(z)\end{align*}
angle(z)

z\begin{align*}z^*\end{align*}
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
MN\begin{align*}M N\end{align*}
M*N

M1\begin{align*}M^{-1}\end{align*}
inv(M)

MT\begin{align*}M^T\end{align*}
M'

det(M)\begin{align*}det(M)\end{align*}
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 A=(1111)\begin{align*}A = \begin{pmatrix}1 & 1\\ 1 & 1\end{pmatrix}\end{align*}. Then

A^2


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

A.^2


will return (12121212)=(1111)\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 y(n)=1sin(x(n))\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 Hide Details
Description
Tags:
Subjects:
Date Created:
Feb 23, 2012
Apr 13, 2016
Files can only be attached to the latest version of section
Image Detail
Sizes: Medium | Original

CK.ENG.ENG.SE.1.Engineering-Matlab.3.4
Here