# Connexions

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

### Recently Viewed

This feature requires Javascript to be enabled.

# Basic Complex and Matrix Operations

Module by: Darryl Morrell. E-mail the author

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+i z1 7 and z2=2eiπ 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.

Table 1: 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.

Table 2: 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 ( 1212 1212 )=( 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".

## Content actions

PDF | EPUB (?)

### What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

#### Definition of a lens

##### Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

##### What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

##### Who can create a lens?

Any individual member, a community, or a respected organization.

##### What are tags?

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks