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.

Section 4.1 Logical Arrays 271<br />

>> k=real(y)~=y<br />

k =<br />

Columns 1 through 10<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 11 through 20<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 21 through 30<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 31 through 40<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 41 through 50<br />

1 1 1 1 1 1 1 1 1 1<br />

Columns 51 through 60<br />

1 1 1 1 1 1 1 1 1 1<br />

Columns 61 through 70<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 71 through 80<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 81 through 90<br />

0 0 0 0 0 0 0 0 0 0<br />

Columns 91 through 100<br />

0 0 0 0 0 0 0 0 0 0<br />

The vector k is a logical vector, hav<strong>in</strong>g logical 1 (true) <strong>in</strong> each position that y<br />

has a complex number. We can use this as an <strong>in</strong>dex <strong>in</strong>to <strong>the</strong> vector x to see what<br />

values <strong>of</strong> x are caus<strong>in</strong>g complex numbers to appear <strong>in</strong> <strong>the</strong> vector y.<br />

>> x(k)<br />

ans =<br />

Columns 1 through 6<br />

-0.9596 -0.8586 -0.7576 -0.6566 -0.5556 -0.4545<br />

Columns 7 through 12<br />

-0.3535 -0.2525 -0.1515 -0.0505 0.0505 0.1515<br />

Columns 13 through 18<br />

0.2525 0.3535 0.4545 0.5556 0.6566 0.7576<br />

Columns 19 through 20<br />

0.8586 0.9596<br />

It would appear that values <strong>of</strong> x between −1 and 1 are creat<strong>in</strong>g complex values <strong>in</strong><br />

<strong>the</strong> vector y. This makes sense because <strong>the</strong> doma<strong>in</strong> <strong>of</strong> <strong>the</strong> function y = √ x 2 − 1

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

Saved successfully!

Ooh no, something went wrong!