<< Chapter < Page | Chapter >> Page > |
m-file environments have excellent support for complex
numbers. The imaginaryunit is denoted by
i
or (as preferred in Electrical Engineering)
j
.
To create complex variables
and
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 is a complex number.
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
.
Then
A^2
will return
,
while
A.^2
will return
.
Given a vector x, compute a vector y having elements
.
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
".
Notification Switch
Would you like to follow the 'Freshman engineering problem solving with matlab' conversation and receive update notifications?