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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Section 4.1 Logical Arrays 285<br />

4.1 Exercises<br />

In Exercises 1-6, first enter <strong>the</strong> follow<strong>in</strong>g<br />

vectors.<br />

>> v=[1,3,5,7], w=[5,2,5,4]<br />

v =<br />

1 3 5 7<br />

w =<br />

5 2 5 4<br />

In each exercise, first predict <strong>the</strong> output<br />

<strong>of</strong> <strong>the</strong> given command, <strong>the</strong>n validate<br />

your response with <strong>the</strong> appropriate<br />

<strong>Matlab</strong> command. Note: The<br />

idea here is not to simply enter <strong>the</strong><br />

command. Ra<strong>the</strong>r, spend some time<br />

th<strong>in</strong>k<strong>in</strong>g, <strong>the</strong>n predict <strong>the</strong> output before<br />

you enter <strong>the</strong> command to verify<br />

your conclusion.<br />

1. v>w<br />

2. v>=w<br />

3. v A=magic(5)<br />

A =<br />

17 24 1 8 15<br />

23 5 7 14 16<br />

4 6 13 20 22<br />

10 12 19 21 3<br />

11 18 25 2 9<br />

In Exercises 7-12, first predict <strong>the</strong><br />

output <strong>of</strong> <strong>the</strong> given command, <strong>the</strong>n<br />

validate your response with <strong>the</strong> appropriate<br />

<strong>Matlab</strong> command. Note: The<br />

idea here is not to simply enter <strong>the</strong><br />

command. Ra<strong>the</strong>r, spend some time<br />

th<strong>in</strong>k<strong>in</strong>g, <strong>the</strong>n predict <strong>the</strong> output before<br />

you enter <strong>the</strong> command to verify<br />

your conclusion.<br />

7.<br />

8.<br />

9.<br />

>> A>14<br />

>> A> (A>3) & (A

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

Saved successfully!

Ooh no, something went wrong!