<< Chapter < Page Chapter >> Page >
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 imaginaryunit is denoted by i or (as preferred in Electrical Engineering) j . To create complex variables z 1 7 and z 2 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 z is a complex number.

Manipulating complex numbers
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.

Common matrix operations
Operation m-file
M N M*N
M -1 inv(M)
M T M'
det( M ) 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 ./ .

Let A 1 1 1 1 . Then A^2 will return AA 2 2 2 2 , while A.^2 will return 1 2 1 2 1 2 1 2 1 1 1 1 .

Given a vector x, compute a vector y having elements y n 1 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 ".

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Pdf generation test course. OpenStax CNX. Dec 16, 2009 Download for free at http://legacy.cnx.org/content/col10278/1.5
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Pdf generation test course' conversation and receive update notifications?

Ask