<< 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
${z}_{1}=7+i$ and
${z}_{2}=2e^{(i\pi )}$ 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) |
$\left|z\right|$ |
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.
Operation | m-file |
---|---|
$MN$ |
M*N |
$M^{-1}$ |
inv(M) |
$M^{T}$ |
M' |
det( $M$ ) |
det(M) |
Some useful facts:
length
and
size
are used to
find the dimensions of vectors and matrices, respectively..*
,
.^
and
./
.Let
$A=\begin{pmatrix}1 & 1\\ 1 & 1\\ \end{pmatrix}$ .
Then
A^2
will return
$\mathrm{AA}=\begin{pmatrix}2 & 2\\ 2 & 2\\ \end{pmatrix}$ ,
while
A.^2
will return
$\begin{pmatrix}1^{2} & 1^{2}\\ 1^{2} & 1^{2}\\ \end{pmatrix}=\begin{pmatrix}1 & 1\\ 1 & 1\\ \end{pmatrix}$ .
Given a vector x, compute a vector y having elements
$y(n)=\frac{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
".
Notification Switch
Would you like to follow the 'Freshman engineering problem solving with matlab' conversation and receive update notifications?