Summary: This module covers basic complex and matrix operations in an m-file environment.
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) |
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
Operation | m-file |
MN | M*N |
M-1 | inv(M) |
MT | 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 ./
.
Let A=(
). Then
A^2
will return
AA=(), while
A.^2
will return
()=().
Given a vector x, compute a vector y having elements y(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