15.11.2014 Views

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

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

270 <strong>Chapter</strong> 4 <strong>Programm<strong>in</strong>g</strong> <strong>in</strong> <strong>Matlab</strong><br />

>> imag(z)<br />

ans =<br />

4<br />

Now, a number r is real if and only if <strong>the</strong> real part <strong>of</strong> r is identical to <strong>the</strong> number<br />

r. For example, set r = 4.<br />

>> r=4<br />

r =<br />

4<br />

Now test if its real part is identical to itself.<br />

>> real(r)==r<br />

ans =<br />

1<br />

Note that <strong>the</strong> logical 1 <strong>in</strong>dicates a “true” response. The real part <strong>of</strong> r equals r.<br />

Thus, r is a real number.<br />

On <strong>the</strong> o<strong>the</strong>r hand, set z = 2 − 3i.<br />

>> z=2-3i<br />

z =<br />

2.0000 - 3.0000i<br />

Test if <strong>the</strong> real part <strong>of</strong> z equals z.<br />

>> real(z)==z<br />

ans =<br />

0<br />

Note that <strong>the</strong> logical 0 <strong>in</strong>dicates a “false” response. The real part <strong>of</strong> z doesn’t<br />

equal z. Thus, z is not a real number, z is complex.<br />

Let’s use this idea to f<strong>in</strong>d <strong>the</strong> positions <strong>in</strong> <strong>the</strong> vector y that hold complex<br />

numbers.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!