<meta http-equiv="refresh" content="1; url=/nojavascript/"> Basic Complex and Matrix Operations | CK-12 Foundation
Dismiss
Skip Navigation
You are reading an older version of this FlexBook® textbook: Engineering: An Introduction to Solving Engineering Problems with Matlab Go to the latest version.

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 z_1 = 7 + j and z_2 = 2e^{j\pi} 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 is a complex number.

Manipulating complex numbers.
m-file
Re(z)
real(z)
Im(z)
imag(z)
mag(z)
abs(z)
\angle(z)
angle(z)
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
M N
M*N
M^{-1}
inv(M)
M^T
M' 
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 A = \begin{pmatrix}1 & 1\\ 1 & 1\end{pmatrix}. Then

A^2

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

A.^2

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

Example 5

Given a vector

x

,

compute a vector

y

having elements y (n) = \tfrac{1}{sin(x(n))}. 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".

Image Attributions

Files can only be attached to the latest version of None

Reviews

Please wait...
Please wait...
Image Detail
Sizes: Medium | Original
 
CK.ENG.ENG.SE.1.Engineering-Matlab.3.4

Original text