Chapter 4: Programming in Matlab - College of the Redwoods
Chapter 4: Programming in Matlab - College of the Redwoods
Chapter 4: Programming in Matlab - College of the Redwoods
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
Section 4.1 Logical Arrays 269<br />
Seems to have worked (see Figure 4.1(a)), but we do receive a warn<strong>in</strong>g at <strong>the</strong><br />
command l<strong>in</strong>e when we run this script.<br />
Warn<strong>in</strong>g: Imag<strong>in</strong>ary parts <strong>of</strong> complex X and/or Y arguments ignored<br />
Complex numbers have seem<strong>in</strong>gly crept <strong>in</strong>to our calculations. They certa<strong>in</strong>ly<br />
don’t exist <strong>in</strong> <strong>the</strong> vector x, because <strong>the</strong> command x=l<strong>in</strong>space(-5,5,200) generates<br />
real numbers between −5 and 5. It must be <strong>the</strong> vector y that conta<strong>in</strong>s <strong>the</strong><br />
complex numbers, but how to f<strong>in</strong>d <strong>the</strong>m?<br />
Real and imag<strong>in</strong>ary parts <strong>of</strong> complex numbers. A complex number has<br />
<strong>the</strong> form a + bi, where i = √ −1. The real part <strong>of</strong> <strong>the</strong> complex number a + bi is<br />
<strong>the</strong> number a. The imag<strong>in</strong>ary part <strong>of</strong> <strong>the</strong> complex number a + bi is <strong>the</strong> number<br />
b. <strong>Matlab</strong> know all about <strong>the</strong> real and imag<strong>in</strong>ary parts <strong>of</strong> complex numbers.<br />
First, check that <strong>the</strong> variable i conta<strong>in</strong>s <strong>the</strong> complex number i. We do this<br />
because i is a popular variable to use <strong>in</strong> scripts and for loops and may have been<br />
set to someth<strong>in</strong>g o<strong>the</strong>r than <strong>the</strong> complex number i.<br />
>> i<br />
ans =<br />
0 + 1.0000i<br />
If you don’t get this result, type clear i and try aga<strong>in</strong>.<br />
Enter z = 3 + 4i.<br />
>> z=3+4i<br />
z =<br />
3.0000 + 4.0000i<br />
The real part <strong>of</strong> z = 3 + 4i is 3.<br />
>> real(z)<br />
ans =<br />
3<br />
The imag<strong>in</strong>ary part <strong>of</strong> z = 3 + 4i is 4.