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.
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.Operation | m-file |
---|---|
MN | M*N |
M-1 | inv(M) |
MT | M' |
det(M) | det(M) |
Some useful facts:
- The functions
length
andsize
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=(
1 | 1 |
1 | 1 |
A^2
will return AA=(2 | 2 |
2 | 2 |
A.^2
will return (12 | 12 |
12 | 12 |
1 | 1 |
1 | 1 |
EXAMPLE 2
Given a vector x, compute a vector y having elements y(n)=
1 |
sin(x(n)) |
y=1./sin(x)
Note that using /
in place of ./
would result in the (common) error "Matrix dimensions must agree
".
0 comments:
Post a Comment