(New page: MATLAB and Complex Numbers Examples To start you may type Format rat i =sqrt(-1) Matlab will return ans = To enter a complex number type c1= 4+5i To find the...)
 
Line 1: Line 1:
MATLAB and Complex Numbers Examples  
+
==MATLAB and Complex Numbers Examples ==
 
+
 
+
To start you may type
+
 
+
 
+
Format rat
+
  
  
 +
Defining terms in matlab
 
i =sqrt(-1)  
 
i =sqrt(-1)  
 
  
 
Matlab will return  
 
Matlab will return  
 +
ans = 0 + 1i
  
 +
EX.
 +
a= 3+2i
 +
Finding the conjugate
 +
conj(a)
 +
Finding the real part
 +
real(a)
 +
Finding the imaginary part
 +
imag(a)
  
 +
==Sample Code==
 +
>> a=3+2i
  
 +
a =3.0000 + 2.0000i
  
ans =
+
>> conj(a)
 
+
+
 
+
 
+
 
+
 
+
To enter a complex number type
+
 
+
 
+
c1= 4+5i
+
 
+
 
+
To find the conjugate of c1 type
+
 
+
 
+
conj(c1)
+
 
+
 
+
You may ask for the real part of a complex number by typing
+
 
+
 
+
real(c1)
+
 
+
 
+
 
+
 
+
Imaginary part of the number can be obtained by typing
+
 
+
 
+
imag(c1)
+
 
+
 
+
To enter a complex matrix, enter it in the same way that you enter a real matrix:
+
 
+
 
+
A= [ 2+i 3-5i, -2; -7i 6+7i 55-12i]
+
 
+
 
+
 
+
 
+
This is what you will see
+
 
+
 
+
A = 2 + 1i 3 - 5i -2   
+
0 - 7i 6 + 7i 55 - 12i
+
 
+
 
+
 
+
 
+
 
+
You may find the real part, imaginary part or the conjugate of a matrix by typing the following commands:
+
 
+
 
+
real(A)
+
 
+
 
+
 
+
 
+
imag(A)
+
 
+
 
+
conj(A)
+
 
+
 
+
To find the conjugate transpose of a matrix use the following command
+
 
+
 
+
A'
+
 
+
 
+
 
+
 
+
The commands det(A), rref(A), roots(p) , poly(A), eig(A) work in the same way that they work for real matrices. Note that A' will provide the conjugate transpose of A.
+
 
+
 
+
Examples:
+
 
+
 
+
Type
+
 
+
 
+
B=[2+3i 3-i 5-7i; 9+i 5+i 2-i; 2-i 3-4i 4+i]
+
 
+
 
+
To find determinant of B type
+
 
+
det(B)
+
 
+
 
+
To find the conjugate transpose of B type
+
 
+
B'
+
 
+
 
+
To find coefficients of the characteristic polynomial of B type
+
 
+
poly(B)
+
 
+
 
+
To find reduced row echelon form of B type
+
 
+
rref(B)
+
 
+
 
+
to find the inverse of B type
+
 
+
inv(B)
+
 
+
 
+
to find eigenvalues of B type
+
 
+
eig(B)  
+
  
 +
ans =3.0000 - 2.0000i
  
 +
>> real(a)
  
 +
ans =3
  
to find eigenvalues and eigenvectors of B type
+
>> imag(a)
  
[V D] = eig(B)
+
ans =2

Revision as of 13:07, 4 September 2008

MATLAB and Complex Numbers Examples

Defining terms in matlab i =sqrt(-1)

Matlab will return ans = 0 + 1i

EX. a= 3+2i Finding the conjugate conj(a) Finding the real part real(a) Finding the imaginary part imag(a)

Sample Code

>> a=3+2i

a =3.0000 + 2.0000i

>> conj(a)

ans =3.0000 - 2.0000i

>> real(a)

ans =3

>> imag(a)

ans =2

Alumni Liaison

Ph.D. 2007, working on developing cool imaging technologies for digital cameras, camera phones, and video surveillance cameras.

Buyue Zhang