Complex and Matrix Operations

Summary: This module covers basic complex and matrix operations in an m-file environment.





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+ andz2=2eπ simply enter z1 = 7 + j and z2 = 2*exp(j*pi)
The table gives an overview of the basic functions for manipulating complex numbers, where z is a complex number.
TABLE 1:Manipulating complex numbers
 m-file
Re(z)real(z)
Im(z)imag(z)
|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 the Table below; in this table, M and N are matrices.
TABLE 2: Common matrix operations
Operationm-file
MNM*N
M-1inv(M)
MTM'
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 1

Let A=(
11
11
). Then A^2 will return AA=(
22
22
)
, while A.^2 will return (
1212
1212
)
=(
11
11
)
.

EXAMPLE 2

Given a vector x, compute a vector y having elements y(n)=
1
sin(x(n))
 . This can be easily be done the command y=1./sin(x) Note that using / in place of ./ would result in the (common) error "Matrix dimensions must agree".

No comments:

Post a Comment