Connexions

You are here: Home » Content » Basic Complex and Matrix Operations
Content Actions

Basic Complex and Matrix Operations

Module by: Darryl Morrell Based on: Basic operations in MATLAB by Anders Gjendemsjø, Darryl Morrell

Summary: This module covers basic complex and matrix operations in an m-file environment.

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+ z1 7 and z2=2eπ z2 2 e 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 zz is a complex number.
Manipulating complex numbers
  m-file
Re(zz) real(z)
Im(zz) imag(z)
|z|z abs(z)
Angle(zz) angle(z)
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.
Common matrix operations
Operation m-file
MNMN M*N
M-1M-1 inv(M)
MTMT M'
det(MM) 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 ./.
Example 1 
Let A= 1 1 1 1 A 1 1 1 1 . Then A^2 will return AA= 2 2 2 2 AA 2 2 2 2 , while A.^2 will return 12121212= 1 1 1 1 12 12 12 12 1 1 1 1 .
Example 2 
Given a vector x, compute a vector y having elements yn=1sinxn yn 1 xn . 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".

Comments, questions, feedback, criticisms?

Send feedback