Summary: This module covers basic complex and matrix operations in an m-file environment.
Note: Your browser may not currently support MathML. See our browser support page for additional details. You can always view the correct math in the PDF version.
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 and z2 = 2*exp(j*pi)
The table gives an overview of the basic
functions for manipulating complex numbers, where
| m-file | |
|---|---|
| Re( |
real(z) |
| Im( |
imag(z) |
abs(z) |
|
| Angle( |
angle(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.
| Operation | m-file |
|---|---|
M*N |
|
inv(M) |
|
M' |
|
| det( |
det(M) |
Some useful facts:
length and size are used to
find the dimensions of vectors and matrices, respectively. .*, .^ and ./.
Let A^2 will return
A.^2 will return
Given a vector x, compute a vector y having elements
y=1./sin(x)
Note that using / in place of ./ would result in the (common) error
"Matrix dimensions must agree".